我正在尝试创建一个excel vba按钮代码,该代码将复制A8:A399
,B8:B399
,C8:C399
,D8:D399
,E8:E399
列中的数据, F8:F399
,G8:G399
,H8:H399
其中一个excel工作簿到另一个工作簿而没有打开它。但我正在使用的代码给出了一条错误消息:
编译错误,预期:列表分隔符或)
并突出显示(:)
中的Set myData = Workbooks.SaveAs(“C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx”)
。请告诉我一个解决方案。
这是我的代码:
Private Sub CommandButton1_Click()
LR = Range("A399").End(xlUp).Row
LR1 = Range("B399").End(xlUp).Row
LR2 = Range("C399").End(xlUp).Row
LR3 = Range("D399").End(xlUp).Row
LR4 = Range("E399").End(xlUp).Row
LR5 = Range("F399").End(xlUp).Row
LR6 = Range("G399").End(xlUp).Row
LR7 = Range("H399").End(xlUp).Row
Dim itemIndex As String
Dim itemNumber As String
Dim itemDetails As String
Dim itemPrice As Single
Dim itemCust_nam As String
Dim itemMobile As String
Dim itemDate As String
Dim itemTime As String
Dim myData As Workbook
Worksheets(“Sheet1”).Select
itemIndex = Range("A8:A" & LR)
itemNumber = Range("B8:B" & LR1)
itemDetails = Range("C8:C" & LR2)
itemPrice = Range("D8:D" & LR3)
itemCust_nam = Range("E8:E" & LR4)
itemMobile = Range("F8:F" & LR5)
itemDate = Range("G8:G" & LR6)
itemTime = Range("H8:H" & LR7)
Set myData = Workbooks.SaveAs(“C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx”)
Worksheets(“Sales”).Select
Worksheets(“Sales”).Range(“A1”).Select
RowCount = Worksheets(“Sales”).Range(“A1”).CurrentRegion.Rows.Count
With Worksheets(“Sales”).Range(“A1”)
.Offset(RowCount, 0) = itemIndex
.Offset(RowCount, 1) = itemNumber
.Offset(RowCount, 2) = itemDetails
.Offset(RowCount, 3) = itemPrice
.Offset(RowCount, 4) = itemCust_nam
.Offset(RowCount, 5) = itemMobile
.Offset(RowCount, 6) = ItemData
.Offset(RowCount, 7) = itemTime
End With
myData.Save
End Sub
答案 0 :(得分:3)
该行有很多错误
“
。您需要使用"
Workbooks
没有.SaveAs
属性如果您尝试保存当前工作簿,请执行此操作
Dim myData As Workbook
Set myData = ThisWorkbook
myData.SaveAs Filename:="C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx", FileFormat:=51
对于文件格式,您可能希望查看THIS链接。