簡體   English   中英

如何在VBA的共享點上引用存儲在Excel文件中的單元格值

[英]How do I reference a Cell value stored in an excel file on sharepoint in VBA

出於對文件進行版本控制的目的,我希望能夠運行一個腳本,該腳本將工作表VC上的單元格A1與運行腳本時存儲在Sharepoint上的版本的同一單元格/工作表進行比較。 使用VBA相當陌生,無法解決該問題,也無法在Google上找到答案。

我要使用的代碼:

Public Sub version_control()

Sheets("VC").Calculate

If Sheets("VC").Range("A1").Value <> (this is where I want it to check cell A1 sheet VC on the Sharepoint file)

MsgBox "Please download the latest version from the Sharepoint"

Application.Quit
End If

End Sub

猜測,您尚未打開SharePoint文件...如果是這樣,請跳過。

但是,如果它是打開的,您可以像其他任何打開的工作簿一樣引用它…例如,這兩個都應該起作用:

debug.Print Workbooks("MySharePointWorkbook.xlsx").Sheets("VC").Range("A1").Value
debug.Print Workbooks.Item(n).Sheets("VC").Range("A1").Value

可能尚未開放,對吧? 沒有進入外部數據鏈路的雜草,我只想獲得的SharePoint文件的完整URL(打開它, ? Activeworkbook.FullName立即窗口),並存儲在該字符串serverFileName是這樣的:

Public Sub version_control()
    Dim serverFileName As String 'obtain url for sharepoint filename, insert below
    Dim valuesAreDifferent As Boolean 'so we can do housekeeping below
    Dim x As New Excel.Application 'make a new session for the sharepoint version
    Dim w As Workbook 'grab-handle for the sharepoint file
    Sheets("VC").Calculate
    valuesAreDifferent = False 'implicit, being explicit
    serverFileName = "http://whatever-domain.com/MySharepointWorkbook.xlsx"
    x.Visible = False 'so it doesn't flash up when checking
    Set w = x.Workbooks.Open(serverFileName) 'open the sharepoint version
    If Sheets("VC").Range("A1").Value <> w.Sheets("VC").Range("A1").Value Then _
        valuesAreDifferent = True
    'housekeeping in case we don't quit
    w.Close
    x.Quit
    Set w = Nothing
    Set x = Nothing
    If valuesAreDifferent Then
        MsgBox "Please download the latest version from the Sharepoint"
        Application.Quit
    End If
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM