【发布时间】:2020-03-08 12:39:13
【问题描述】:
我正在尝试从工作簿中的特定单元格获取数据,然后保存到我们公司 SharePoint 上工作簿中的新行。
我认为我的主要问题是“查找”SharePoint 文档。我在下面的代码中有一个示例路径。
我从一个网站上提取代码,以便在工作簿之间共享,这是我的代码中被大量评论的部分,也是我认为可能存在问题的区域。
Sub depositSummaryUpdater()
ActiveSheet.Unprotect "password"
Dim managerName As String
managerName = ActiveSheet.Cells(6, 4).Value
Dim depositActual As Currency
depositActual = ActiveSheet.Cells(11, 9).Value
Dim depositRevel As Currency
depositRevel = ActiveSheet.Cells(18, 3).Value
Dim depositVariance As Currency
depositVariance = ActiveSheet.Cells(15, 3).Value
Dim hundredCountDeposit As Currency
hundredCountDeposit = ActiveSheet.Cells(12, 7).Value
Dim fiftyCountDeposit As Currency
fiftyCountDeposit = ActiveSheet.Cells(11, 7).Value
Dim twentyCountDeposit As Currency
twentyCountDeposit = ActiveSheet.Cells(10, 7).Value
Dim tenCountDeposit As Currency
tenCountDeposit = ActiveSheet.Cells(9, 7).Value
Dim fiveCountDeposit As Currency
fiveCountDeposit = ActiveSheet.Cells(8, 7).Value
Dim twoCountDeposit As Currency
twoCountDeposit = ActiveSheet.Cells(7, 7).Value
Dim oneCountDeposit As Currency
oneCountDeposit = ActiveSheet.Cells(6, 7).Value
Dim quarterCountDeposit As Currency
quarterCountDeposit = ActiveSheet.Cells(9, 10).Value
Dim dimeCountDeposit As Currency
dimeCountDeposit = ActiveSheet.Cells(8, 10).Value
Dim nickelCountDeposit As Currency
nickelCountDeposit = ActiveSheet.Cells(7, 10).Value
Dim pennyCountDeposit As Currency
pennyCountDeposit = ActiveSheet.Cells(6, 10).Value
Dim tillDate As Date
tillDate = Format(ActiveSheet.Cells(4, 4), "YY-MM-DD")
Dim wsDest As Worksheet
Dim destLastRow As Integer
'Dim depositPathString As String
'depostPathString = "https://ourcorporatesharpointaddress.sharepoint.com/sites/tills/Shared%20Documents/Safe%20Deposit/Safe_Deposit_Summary"
'Set variables for destination sheet
'Set wsDest = Workbooks(depositPathString).Worksheets("Deposit Summary")
Set wsDest = Workbooks("https://ourcorporatesharepointaddress.sharepoint.com/sites/tills/Shared%20Documents/Safe%20Deposit/Safe_Deposit_Summary").Worksheets("Deposit Summary")
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
destLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'3. Copy & Paste Data
Set wsDest.Cells(destLastRow, 1) = tillDate
Set wsDest.Cells(destLastRow, 2) = hundredCountDeposit
Set wsDest.Cells(destLastRow, 3) = fiftyCountDeposit
Set wsDest.Cells(destLastRow, 4) = twentyCountDeposit
Set wsDest.Cells(destLastRow, 5) = tenCountDeposit
Set wsDest.Cells(destLastRow, 6) = fiveCountDeposit
Set wsDest.Cells(destLastRow, 7) = twoCountDeposit
Set wsDest.Cells(destLastRow, 8) = oneCountDeposit
Set wsDest.Cells(destLastRow, 9) = quarterCountDeposit
Set wsDest.Cells(destLastRow, 10) = dimeCountDeposit
Set wsDest.Cells(destLastRow, 11) = nickelCountDeposit
Set wsDest.Cells(destLastRow, 12) = pennyCountDeposit
Set wsDest.Cells(destLastRow, 13) = depositActual
Set wsDest.Cells(destLastRow, 14) = depositRevel
Set wsDest.Cells(destLastRow, 15) = depositVariance
Set wsDest.Cells(destLastRow, 16) = managerName
ActiveSheet.Protect "password", True, True
End Sub
【问题讨论】:
-
您的
wsdest工作簿上没有扩展名。您需要选择一个实际的工作簿。 -
您是否从 SharePoint 打开目标工作簿?在某些时候您需要致电
workbooks.Open()
标签: excel vba sharepoint sharepoint-online