[英]DoCmd.TransferSpreadsheet Range messing up Name adding $ instead of?
Everytime I try and put names in the ranges it keeps adding a $ instead of a !每次我尝试将名称放在范围内时,它都会不断添加 $ 而不是 ! like I typed it.
就像我输入的一样。 Using office 365. Running the code inside excel trying to get it to import into Access but I keep getting an error.
使用 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
Results from Immediate Window Show Correct立即窗口显示的结果正确
Print PageName
打印页面名称
Line14
Print fullrange
$A$1:$G$18
print xclam
Line14!$A$1:$G$18
Print PageName
Line14
But this Error Shows Up enter image description here Not sure what Else to do但出现此错误在此处输入图像描述不知道该怎么做
If data with headers starts at A1
, you don't need cell ranges.如果带有标题的数据从
A1
开始,则不需要单元格区域。 So simply set up Range
argument as Line14!
所以只需将
Range
参数设置为Line14!
. .
But if do set up cell ranges, you do not need $
.但是,如果确实设置了单元格范围,则不需要
$
。 So simply set up Range
as Line14!A1:G18
.所以只需将
Range
设置为Line14!A1:G18
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.