vba 代码给了我编译错误,预期:列表分隔符或)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36398578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:19:54  来源:igfitidea点击:

Code gives me Compile Error, Expected: List Separator or )

excelvba

提问by Riufaan

I am trying to create an Excel VBA button code which will copy a data in columns A8:A399, B8:B399, C8:C399, D8:D399, E8:E399, F8:F399, G8:G399, H8:H399one of the excel workbook to another workbook without opening it. But the Code I am using gives me an error message saying:

我试图创建一个Excel VBA代码按钮将在列复制数据A8:A399B8:B399C8:C399D8:D399E8:E399F8:F399G8:G399H8:H399在Excel中的一个工作簿到另一个工作簿,而无需打开它。但是我使用的代码给了我一条错误消息:

Compile Error, Expected: List Separator or )

编译错误,预期:列表分隔符或)

and it highlights the (:)in Set myData = Workbooks.SaveAs(“C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx”). Please tell me a solution.

它突出显示了(:)in Set myData = Workbooks.SaveAs(“C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx”)。请告诉我一个解决方案。

Here is my Code:

这是我的代码:

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

回答by Siddharth Rout

There are lot of errors with that line

那条线有很多错误

  1. You are using . You need to use "
  2. Workbooksdo not have the .SaveAsproperty
  1. 您正在使用. 你需要使用"
  2. Workbooks没有.SaveAs财产

If you are trying to save the current workbook then do this

如果您尝试保存当前工作簿,请执行此操作

Dim myData As Workbook

Set myData = ThisWorkbook
myData.SaveAs Filename:="C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx", FileFormat:=51

For file formats, you may want to see THISLink.

对于文件格式,您可能需要查看链接。