[英]DoCmd.TransferSpreadsheet Range messing up Name adding $ instead of?
每次我嘗試將名稱放在范圍內時,它都會不斷添加 $ 而不是 ! 就像我輸入的一樣。 使用 office 365。在 excel 中運行代碼試圖將其導入 Access,但我一直收到錯誤消息。
Sub ImportLine14()
Dim accappl As Access.Application
Dim strpathdb As String
Dim strpathxls As String
'Dim myrange As String, myrow1 As String, myrow2 As String
'Dim fullRange As Range
strpathdb = "\\US5MS0005\_Group Folders\Public\Production Data\Production Database\dbPlantData_be.accdb"
'path to the upload file
strpathxls = "\\US5MS0005\_Group Folders\Public\Production Schedule SAP\Production Schedule 2022 DugTest.xlsm"
Set accappl = New Access.Application
accappl.OpenCurrentDatabase strpathdb
Dim Page As Worksheet
Dim lRow As Long, LCol As Long
Dim fullrange As String
Dim PageName As String
'fullrange = Worksheets("Line14P").Range(Worksheets("Line14P").Cells(1, 1), Worksheets("Line14P").Cells(lRow, LCol))
PageName = Worksheets("Line14").Name
lRow = Worksheets("Line14").Range("A" & Rows.Count).End(xlUp).Row
LCol = Worksheets("Line14").Cells(2, Columns.Count).End(xlToLeft).Column
fullrange = Worksheets("Line14").Range(Worksheets("Line14").Cells(1, 1), _
Worksheets("Line14").Cells(lRow, LCol)).Address
xclam = PageName & "!" & fullrange
accappl.DoCmd.TransferSpreadsheet TransferType:=acImport, _
SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:="tblProcessOrder", Filename:=strpathxls, _
HasFieldNames:=True, Range:=PageName & "!" & fullrange
accappl.Quit
End Sub
立即窗口顯示的結果正確
打印頁面名稱
Line14
Print fullrange
$A$1:$G$18
print xclam
Line14!$A$1:$G$18
Print PageName
Line14
但出現此錯誤在此處輸入圖像描述不知道該怎么做
如果帶有標題的數據從A1
開始,則不需要單元格區域。 所以只需將Range
參數設置為Line14!
.
但是,如果確實設置了單元格范圍,則不需要$
。 所以只需將Range
設置為Line14!A1:G18
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.