编写一个macros以在一个文件夹中的500多个工作簿中更改字体和大小

我在一个文件夹中有500多个.xlsx文件; 他们有相同的格式(图表和表格)。 我需要做的是改变特定单元格的字体,大小和alignment方式。 我从互联网上得到了一些macros,但似乎没有一个可以工作。 我想我得到的最接近的是:

 Sub Font_Style() Dim wb As Workbook, sh As Worksheet, fPath As String, fName As String fPath = "C:\xxx\1234\" fName = Dir(fPath & "*.xlsx") Do Set wb = Workbooks.Open(fName) Set sh = wb.Sheets("Empty Form") With sh.Range("X17") .Font.Size = 20 .Font.Name = "Arial" .Font.Bold = True .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With wb.Close True fName = Dir Loop While fName <> "" End Sub 

你可以用这个

 Sub formatchange() Dim objFSO As Object Dim objFolder As Object Dim objFile As Object Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("your path") Application.ScreenUpdating=False 'for a fster code For Each objFile In objFolder.files Workbooks.Open (objFile) 'put your formatting code here ActiveWorkbook.Close savechanges:=True Next 'Clean up! Set objFolder = Nothing Set objFile = Nothing Set objFSO = Nothing Application.ScreenUpdating=True 'turn on updatin again End Sub