vbasharepointcheckin

How to check-in a file on sharepoint?


I have written the following code for checking-in of files through VBA on Sharepoint.

Dim strWkbCheckIn As String

strWkbCheckIn = spBASE_URL + spDOC_LIB + "/" + spFILE_NAME

' Determine if workbook can be checked in.
If Workbooks(strWkbCheckIn).CanCheckIn = True Then
   Workbooks(strWkbCheckIn).CheckIn
   MsgBox ("checked in.")
Else
   MsgBox ("This file cannot be checked in ")
End If

But it is showing the following error:

Run-time error '9':
Subscript out of range

I have already checked that the file does exist on the sharepoint. But still getting this error. Just a wild guess, is it possible, that since the file and checked-out to me, it is not visible to the program?


Solution

  • This should do it for you.

    Sub testing()
        Dim docCheckOut As String
        'docCheckOut = "//office.bt.com/sites/Training/Design Admin/Training Plan/adamsmacro.xlsm"
        docCheckOut = "http://excel-pc:43231/Shared Documents/ExcelList.xlsb"
        Call UseCheckOut(docCheckOut)
        Call UseCheckIn(docCheckIn)
    End Sub
    
    Sub UseCheckOut(docCheckOut As String)
         ' Determine if workbook can be checked out.
        If Workbooks.CanCheckOut(docCheckOut) = True Then
            Workbooks.CheckOut docCheckOut
        Else
            MsgBox "Unable to check out this document at this time."
        End If
    End Sub
    
    Sub UseCheckIn(docCheckIn As String)
         ' Determine if workbook can be checked out.
        If Workbooks.CanCheckIn(docCheckIn) = True Then
            Workbooks.CheckIn docCheckIn
        Else
            MsgBox "Unable to check in this document at this time."
        End If
    End Sub