1
votes

I have an application with a button. This button refers to an Excel document I have on a SharePoint. However, it will download the file which means it's read-only. Now, there's an option in the SharePoint to open the file in edit-mode and I would like my button to do the same - how can I use the link href to link to the file and open it in edit-mode?

enter image description here

How can I do the same action as the "Edit in Microsoft Excel" using a button outside the SharePoint? Like a link to the file that will open it in editing mode.

2

2 Answers

2
votes

This does not "Edit in Microsoft Excel" option but the "Check Out".

To "Edit in Microsoft Excel" the solution is unbelievably easy. In the Workbook_Open just do ActiveWorkbook.LockServerFile. The documentation for this command says it locks the workbook, but in this case it does the exact opposite, it simply executes the Edit bar question.

Private Sub Workbook_Open()

'The following command is equivalent to hitting the "Edit" bar 
'that comes up when you open an Excel file by clicking on it in SharePoint,
'which is equivalent to "Edit in Microsoft Excel" (not CheckOut)

ActiveWorkbook.LockServerFile

End Sub
1
votes

The Workbooks object has the functions you need: CanCheckOut to make sure it's available, and CheckOut for opening the file for editing

This code will take the name of the file (like http://server:port/PathToFile/myExcelFile.xlsx) and open it if possible

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

vbscript for web page:

set objExcel = CreateObject("Excel.Application")
drPath = "server\file"
if (objExcel.Workbooks.CanCheckOut(drPath) = True) then
    objExcel.Application.Workbooks.CheckOut drPath //note - may need to open first
    objExcel.Application.Workbooks.Open drPath
else
    msgbox("Unable to checkout SharePoint file: " & file.name & ". Please contact an administrator.")
end if

also discussed in more detail on this page, but that goes far beyond my knowledge