[英]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.