尝试在程序开始时检查并设置窗口缩放级别。 仅当窗口缩放级别设置为 200% 时,该过程才会启动。
试着说:
如果当前级别为“正确”,则到目前为止的代码才会开始。
如何构建它,以便它在更改缩放级别后也启动?
Sub AddChart()
'...
If Not ActiveWindow.Zoom = 200 Then
MsgBox "Set Window Zoom to: 200%", vbOKCancel
Else
ActiveWindow.Zoom = 200
Set ws = ActiveSheet
With ws
'...
End With
End If
End Sub
您的代码测试缩放是否设置为 200。如果不是,它会警告您更改它。如果是的话,无论如何都会设置它..?
您应该使用:
If Not ActiveWindow.Zoom = 200 Then
MsgBox "Setting Window Zoom to: 200%", vbOKOnly
ActiveWindow.Zoom = 200
End If
vbOkOnly
Sub AddChart()
'...
If Not ActiveWindow.Zoom = 200 Then
MsgBox "Setting Window Zoom to: 200%", vbOKOnly, "Info"
ActiveWindow.Zoom = 200
End If
Set ws = ActiveSheet
With ws
'...
End With
End Sub
vbOkCancel
Sub AddChart()
'...
Dim Result As Integer
If Not ActiveWindow.Zoom = 200 Then
Result = MsgBox("Set Window Zoom to: 200%", vbOKCancel, "Info")
If Result = vbOK Then
ActiveWindow.Zoom = 200
Else: Exit Sub
End If
End If
Set ws = ActiveSheet
With ws
'...
End With
End Sub