I have some VBA i\'m trying to get to check out a workbook before making changes. The VBA code sits in its own work book, and is activated by a user opening the other work book
Sub CheckOutAndOpenFromSharePoint()
Dim FilePath As String
Dim FileName as string
FilePath = "http://Sharepoint site/Folder Name On SharePoint Site/"
FileName = "Testing.xlsx"
If Workbooks.CanCheckOut(FilePath & FileName) = True Then
Workbooks.CheckOut "http://Sharepoint%20site/Folder%20Name%20On%20SharePoint%Site/Testing.xlsx"
Workbooks.Open Filename:=FilePath & FileName
Else
MsgBox FileName & " can't be checked out at this time.", vbInformation
End If
End Sub
I've found through trial and error that Workbooks.CanCheckOut (Filename:= FullName)
where FullName is the URL for the SharePoint file only works for files that are not open in the current instance of Excel.
The method will always return False
if you have the file open in the current instance of Excel which is obviously the case here.
Workbooks.CheckOut (ActiveWorkbook.FullName)
opens the file, checks it out and then inexplicably, closes the file. So opening and checking out a SharePoint file becomes a 3 step process.
Sub CheckOutAndOpen()
Dim TestFile As String
TestFile = "http://spserver/document/Test.xlsb"
If Workbooks.CanCheckOut(TestFile) = True Then
Workbooks.CheckOut(TestFile)
Workbooks.Open (TestFile)
Else
MsgBox TestFile & " can't be checked out at this time.", vbInformation
End If
End Sub
This is all a bit counter intuitive because when working manually with SharePoint files you have to open them to see if they can be checked out and then perform the check-out operation.
Neither MSDN or Excel VBA help mention that the Workbooks.CanCheckOut (Filename:= FullName)
method always returns False if you have the file open in the current instance of Excel.