check in/ out an excel doc on sharepoint

ADAMC

Well-known Member
Joined
Mar 20, 2007
Messages
1,169
Office Version
  1. 2013
Platform
  1. Windows
Hi all,
I have done some background on this but cant seem to get it working :(
can someone help me?

I have a doc on sharepoint called adamc.xlsx
when I open the doc i would like the workbook open event to check the document out for editing

on the workbook close event i would like it to be checked back in...

Been playing arond with Workbooks.CancheckOut but ive completely lost the plot.....

Any help greatly appreciated.

Thank you!!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Andrew,
thanks for the link not so sure I have my syntax correct, based on the example you provided:

Sub UseCanCheckOut(docCheckOut As String)

' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(Filename:=adamc.xlsm) = True Then
Workbooks.CheckOut (Filename:=adamc.xlsm)
Else
MsgBox "You are unable to check out this document at this time."
End If

End Sub

Would the filename be the URL from sharepoint rather than the filename itself?
The above doesnt seem to do anything.

Sorry if thats a silly question.....Thanks.
 
Upvote 0
I would have thought you could use ThisWorkbook.FullName (or Me.FullName if the code is in the ThisWorkbook module).
 
Upvote 0
Suprising even myself that actually makes sense to me. Thanks Andrew. :)

Based on the links you have provided and various googling I have cobbled together this code:

Sub test()
Dim docCheckOut As String
docCheckOut = "//office.bt.com/sites/Training/Design%20Admin/Training%20Plan/adamsmacro.xlsm"

Call UseCheckOut(docCheckOut)
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

Unfortunately although I can clearly see the excel workbook is NOT checked out the macro above always returns the Msgbox "unable to check out this document at this time"

Anyone have any idea why?

When you first open a doc from sharepoint it always shows as readonly.....
Could this be the reason why it doesnt work? can a macro run on a file which is read only?

If anyone could shed any light id be really grateful.

Thanks
 
Upvote 0
Hi Andrew,

I tried your suggestion, again the macro runs but only returns the Msgbox "unable to check out the document at this time"

Is it possible to post a screenshot, might be easier if I show a screenshot of what Im looking at?

Thanks
 
Upvote 0
Hi Andew,

Apologies, I completely forgot to respond.

Thisworkbook.fullname actually returned the URL of the excel file stored in sharepoint as I had in my original code.

In case anyone is interested, I dont know why or how but the cancheckout method only seems to work when triggered from a workbook other than the work book you are checking out.
I.E = A workbook can not check itself out. When I run the code from a seperate workbook, it actually works fine.

Thanks for your efforts in helping me.

P.S If anyone knows why the cancheckout method cant run from the same workbook it is checking out id really like to know thanks :)
 
Upvote 0
Hi Andew,

Apologies, I completely forgot to respond.

Thisworkbook.fullname actually returned the URL of the excel file stored in sharepoint as I had in my original code.

In case anyone is interested, I dont know why or how but the cancheckout method only seems to work when triggered from a workbook other than the work book you are checking out.
I.E = A workbook can not check itself out. When I run the code from a seperate workbook, it actually works fine.

Thanks for your efforts in helping me.

P.S If anyone knows why the cancheckout method cant run from the same workbook it is checking out id really like to know thanks :)



Anyone vouge for this? is this actually the case? Any thoughts on forced checkout and forced checkin upon opening from Sharepoint and closing the file?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top