Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim strFolder As String
Dim MyFile As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder"
.InitialFileName = "d:\"
If .Show Then
strFolder = .SelectedItems(1)
End If
End With
If strFolder = "" Then Exit Sub
MyFile = Dir(strFolder & "*.xls") '第一个文件路径
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(strFolder & MyFile)
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Range("A1:D1").Select
Selection.NumberFormatLocal = "0.00_ "
xlApp.SaveWorkspace
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet1 = Nothing
Do While MyFile <> "" '循环其他文件路径
MyFile = Dir
If MyFile = "" Then
Exit Do
End If
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(strFolder & MyFile)
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Range("A1:D1").Select
Selection.NumberFormatLocal = "0.00_ "
xlApp.SaveWorkspace
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet1 = Nothing
Loop
多张表格一起选中,然后设置格式就好了。