简体   繁体   中英

vba Excel - How to Check if a SharePoint Website File is Open

I've searched the internet for the answer to this and keep running into issues getting it to work.

I need to check if a file at the below location is open/locked, and then have the code wait 15 seconds and then try again. Right now if someone else has the file open a dialog box opens asking if I want to open read only, which I don't want. I tried using Application.DisplayAlerts = False to get the message not to appear but that didn't seem to work. So I have two main issues:

  1. Checking if the file is open and waiting to try again.
  2. Stop the dialog box from opening asking to open as read only.

Workbooks.Open filename:= _ " https://somecorporatewebsite/sites/TNKYWest/Engr/ASE%20Updates/Shared%20Documents/ASENW Updater.xlsx"

  1. Try something like this:

From MSDN site: https://msdn.microsoft.com/en-us/library/office/ff193284.aspx

Sub UseCanCheckOut(docCheckOut As String) 
Dim docCheckout
set docCheckout="File name to open"
' Determine if workbook can be checked out. 
If Workbooks.CanCheckOut(Filename:=docCheckOut) = True Then 
Workbooks.CheckOut (Filename:=docCheckOut) 
Else 

Found at the MSDN Website: https://msdn.microsoft.com/en-us/library/office/ff822851.aspx

Application.Wait(Now + TimeValue("0:00:10")) 
Workbooks.CheckOut (Filename:=docCheckOut) 'Try to check the file out again.
End If 

End Sub
  1. This part is covered in the

    IF workbooks.cancheckout(filename:=docCheckout)=true then workbooks.checkout ' method in part 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM