0

I have a rather odd situation, the below code can successfully checkout a file from sharepoint to Excel...

Private sub checkoutfromSP()
Dim loc as String
loc = "Location"

if Workbooks.CanCheckOut(loc) = true then
Workbooks.CheckOut loc
end if

However how does this translate into Access? I always receive the error "This document cannot be checked out" with the following code?

Dim objXL as Excel.Application
Dim loc as String

loc = "Location"
objXL = new Excel.Application

if objXL.Workbooks.CanCheckOut(loc) = True then
objXL.Workbooks.CheckOut loc
end if

Reason for the checkout via Access is there are a few pieces of data that need dropped into Excel from Access, however as the Excel file is on sharepoint I need to checkout/checkin to submit the changes.

1 Answer 1

1
+50

Open the document with your Excel instance before checking it out and it should work for you:

Dim objXL As Excel.Application
Dim objWB As Excel.Workbook 'NEW
Dim loc As String

loc = "Location"

Set objXL = New Excel.Application  'Make sure you use Set here

If objXL.Workbooks.CanCheckOut(loc) = True Then
    Set objWB = objXL.Workbooks.Open(loc)  'NEW
    objXL.Workbooks.CheckOut loc
End If

When you check the workbook back in with the line objWB.CheckIn, Excel automatically closes the Workbook object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.