1

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?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Dimi Ansari
  • 310
  • 3
  • 16

1 Answers1

2

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
ASH
  • 20,759
  • 19
  • 87
  • 200
  • 2
    What references are needed for this to work? CanCheckIn isn't usually a workbook method.... – Selkie Oct 25 '19 at 18:00