LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Check out Excel file from SharePoint; if no other Excel file is op

Im opening (checking out) an Excel file from SharePoint and trying to apply
a test to see if there is another Excel file in SharePoint already open. If
there is an Excel file open, I want a prompt to be displayed to a user. If
there is currently no Excel file checked out, then the user can open the file
without any problem. Heres the code I have so far:

Option Explicit

Sub UseCanCheckOut()
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim xlFile As String

xlFile = "https://globalconsumer.w.net/sites/Shared%20Documents/test/" &
ActiveWorkbook.Name

If Workbooks.CanCheckOut(ActiveWorkbook.Path & "/" & ActiveWorkbook.Name) =
True Then
Workbooks.CheckOut (ActiveWorkbook.Path & "/" & ActiveWorkbook.Name)
MsgBox "Is checked out to you."
Else
MsgBox "Cannot be checked out to you."
End If

'Determine if workbook can be checked out.
If Workbooks.CanCheckOut(xlFile) = True Then
Workbooks.CheckOut xlFile
Set xlApp = New Excel.Application
xlApp.Visible = True
Set wb = xlApp.Workbooks.Open(xlFile, , False)
' MsgBox wb.Name & " is checked out to you."
' Else
' MsgBox "You are unable to check out this document at this time."
End If

Call MyMacro

End Sub

Sub MyMacro()
If
IsFileOpen("https://globalconsumer.w.net/sites/Shared%20Documents/test/" &
ActiveWorkbook.Name) Then
' Display a message stating the file in use.
MsgBox "Another similar file is already in use!"

End If

End Sub

Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer

On Error Resume Next
filenum = FreeFile()

Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0

Select Case errnum
Case 0
IsFileOpen = False

Case 70
IsFileOpen = True

End Select

End Function

I think it's going to be something like that. I'm certainly not an expert
with SharePoint!!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to programmically upload Excel file to Sharepoint? Hii Sing Chung Excel Programming 4 September 17th 09 03:57 AM
Open Sharepoint Hosted Excel File, in Excel, Using VBA PatK Excel Programming 3 June 2nd 09 02:30 PM
VBA Code to open an Excel file on a sharepoint site Vit[_2_] Excel Programming 4 September 4th 08 08:01 AM
Saving an XML file to a sharepoint location using VBA in excel [email protected] Excel Programming 1 May 14th 08 09:17 PM
code to check file size everytime an Excel file is opened Kaiser[_2_] Excel Programming 2 July 30th 06 05:46 PM


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"