This code works perfectly for me to check if the file can be checked out. The problem is the CheckIn part....I'm getting an error: Method or Data Member not found and CanCheckIn is highlighted. I have tried substituting the FileName for the docCheckIn variable as suggested below without any luck as well. Any help would be appreciated.
Thanks in Advance,
Don
VBA Code:
Option Explicit
'https://stackoverflow.com/questions/51606517/how-to-check-in-a-file-on-sharepoint
'https://stackoverflow.com/questions/55120943/sharepoint-checkin-file-method-or-data-member-not-found
'Set WbObj = Workbooks("workbookname.xls") 'if it's open
'Set WbObj = Workbooks.Open(docCheckIn) 'if it isn't open
'edit: Workbooks(docCheckIn).CanCheckIn will work but the docCheckIn must be a workbook name, not full path. Alternatively set the workbook as object using your docCheckIn path and use WbObj.CanCheckIn
'edit2: bear in mind that the Workbooks.checkin docCheckIn will have to be changed the same way to either Workbooks("workbookname.xls").checkin or WbObj.checkin
Sub SharePointCheckOutIn()
Dim docCheckOut As String
Dim docCheckIn As String
'docCheckIn = "WorkMix_Re-Forecast_2022.xlsx"
docCheckOut = "http://kb/sites/PMO/Metrics and Reporting/2022 Financials/WorkMix_Re-Forecast_2022.xlsx"
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)
docCheckIn = "WorkMix_Re-Forecast_2022.xlsx"
' Determine if workbook can be checked in.
If Workbooks.CanCheckIn(docCheckIn) = True Then '<<<<Method or Data Member Not Found and CanCheckIn is highlighted
Workbooks.CheckIn docCheckIn
Else
MsgBox "Unable to check in this document at this time."
End If
End Sub
Thanks in Advance,
Don