我想運行此代碼的VB代碼,但它給了我下面提到的錯誤。在文件夾中的所有xls文件上運行Excel宏
任何幫助將不勝感激,因爲我是新來的VB。
**Code :**
Option Explicit
Public Sub ReadExcelFiles(FolderName As String)
Dim FileName As String
' Add trailing \ character if necessary
'
If Right(FolderName, 1) <> "\" Then FolderName = FolderName & "\"
FileName = Dir(FolderName & "*.xls")
Do While FileName <> ""
Workbooks.Open (FolderName & FileName)
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A1").Select
ActiveCell.FormulaR1C1 = "Name"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Anil"
Range("A2").Select
End Sub
Workbooks(FileName).Close
FileName = Dir()
Loop
End Sub
Public Sub test()
ReadExcelFiles ("C:\Macro")
End Sub
命令:cscript C:\宏\ test.vbs
結果:錯誤,2號線,38字符,預計 ')'