VBA 焦点居A1,sheet居sheet1, 预览大小调整100% ,设置打印页脚水印(操作同一文件夹下所有excel)

Sub BtnChooseFolder_Click()

Worksheets("util").Cells(6, 2).Value = ""

Dim folderPath As String
If Application.FileDialog(msoFileDialogFolderPicker).Show Then
folderPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End If
If folderPath = "" Then
Exit Sub
End If
Worksheets("util").Cells(6, 2).Value = folderPath
End Sub

 

Sub format()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim filePath
filePath = Worksheets("util").Cells(6, 2).Value
Dim ssBook As Workbook
Dim fileName As String
fileName = Dir(filePath & "\" & "*.xlsx")

Dim fileNum As Integer
' deal with each file
Do While fileName <> ""
Set ssBook = Workbooks.Open(filePath & "\" & fileName)
Dim ssSheet As Worksheet
' deal with each sheet
For Each ssSheet In ssBook.Worksheets
' update copyright
Application.PrintCommunication = False
ssSheet.PageSetup.LeftFooter = "(C)Copyright FUJITSU Limited 2022"
Application.PrintCommunication = True
' go to focus
If ssSheet.Visible = True Then
Application.Goto ssSheet.Range("A1"), False
End If
' go to viewsize
ssSheet.Activate
ActiveWindow.Zoom = 100
Next
' go to focus
ssBook.Worksheets(1).Select
' save and close
fileNum = fileNum + 1
ssBook.Save
ssBook.Close
fileName = Dir
Loop
MsgBox fileNum & " files successed"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

posted @ 2022-06-21 14:26  人鬼情未了  阅读(176)  评论(0编辑  收藏  举报