我复制并编辑了我在此stackoverflow问题中找到的一些代码: Loop through all worksheets in all Excel workbooks in a folder to change the font, font size, and alignment of text in all cells
虽然代码取消/保护工作表(仍然是正在进行的工作,最终将是一个切换),当我稍后打开工作簿时,工作簿窗口被隐藏,我必须手动按下取消隐藏窗口& #39; '视图中的图标带。我无法在代码中看到触发“隐藏”的任何内容。有没有人有任何线索如何预防/解决这个问题?
我的版本:
Sub fAMWToggleProtection()
Const fPath As String = "S:\SHARED\Cidmls\MasterMix Section\Copy of Master Mix templates for testing\"
Dim sh As Worksheet
Dim sName As String
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
End With
sName = Dir(fPath & "*.xls*")
Do Until sName = ""
With GetObject(fPath & sName)
For Each sh In .Worksheets
With sh
.Visible = True
.Unprotect Password:="icpmr"
' .Protect Password:="icpmr"
End With
Next sh
' .Save
' .Close True
Debug.Print sName
End With
sName = Dir
Loop
With Application
.EnableEvents = True
.ScreenUpdating = True
.DisplayAlerts = True
End With
MsgBox "Complete", vbOKOnly, "Uprotect all sheets"
On Error GoTo 0
Exit Sub
fAMWToggleProtection_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in fAMWToggleProtection of Module1"
End Sub
答案 0 :(得分:0)
尝试:
With GetObject(fPath & sName)
.Windows(1).Visible = True ' <-- Not tested, but assuming this is a Workbook object
For Each sh In .Worksheets