gpt4 book ai didi

excel - vb.net Office365共享点检查文件由用户打开

转载 作者:行者123 更新时间:2023-12-04 10:26:35 25 4
gpt4 key购买 nike

我有以下脚本可以从 office365 Sharepoint 访问 excel 文件。

dim objApp2 As Excel.Application
dim objBook2 As Excel._Workbook
dim objBooks2 As Excel.Workbooks
dim objSheets2 As Excel.Sheets
dim objSheet2 As Excel._Worksheet

link="sharepointlink"
objApp2 = New Excel.Application()
objBooks2 = objApp2.Workbooks
objBook2 = objBooks2.Open(link, [ReadOnly]:=False)
objSheets2 = objBook2.Worksheets
ws2 = objSheets2("Data")
Dim valoare As Integer
valoare = Int(ws2.Range("a1").Value)
ws2.Range("a1").Value = valoare + 1
objBook2.SaveAs()
objBook2.Close(False)

我有一个问题:如果有人访问我的链接并打开文件,无论是在 Sharepoint 上还是在本地打开,我在尝试关闭对象或保存文件时都会收到错误消息。

当我尝试保存时,如何检查文件是否被某人打开,或者是否有其他方法可以访问该文件?

最佳答案

欢迎来到本站。 ReadOnly 属性应该告诉您是否有其他人打开它,尤其是当您说您不希望它打开时。您可能最终需要切换到共享工作簿,但这应该可以解决问题。

dim objApp2 As Excel.Application
dim objBook2 As Excel._Workbook
dim objBooks2 As Excel.Workbooks
dim objSheets2 As Excel.Sheets
dim objSheet2 As Excel._Worksheet

link="sharepointlink"
If IsFileInUse(link) then
MsgBox "Cannot update Excel file"
Exit Sub 'End
End If
objApp2 = New Excel.Application()
objBooks2 = objApp2.Workbooks
objBook2 = objBooks2.Open(link, [ReadOnly]:=False)
objSheets2 = objBook2.Worksheets
ws2 = objSheets2("Data")
Dim valoare As Integer
valoare = Int(ws2.Range("a1").Value)
ws2.Range("a1").Value = valoare + 1
objBook2.SaveAs()
objBook2.Close(False)



Public Function IsFileInUse(sFile As String) As Boolean
Try
Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
End Using
Catch Ex As Exception
Return True
End Try
Return False
End Function

关于excel - vb.net Office365共享点检查文件由用户打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60616075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com