你可以尝试像
Sub test()
MsgBox Application.ActiveWindow.ActivePane.VisibleRange.AddressLocal
End Sub
Run Code Online (Sandbox Code Playgroud)
就我而言,它会打开包含内容的msgbox,$A$271:$X$312
希望对您有所帮助。
编辑:
好的,尝试用XY坐标找出它,然后执行以下操作:
Sub TestPixel()
With Range(ActiveWindow.ActivePane.VisibleRange.AddressLocal)
Debug.Print .Left, .Top
Debug.Print .Left + .Width, .Top + .Height
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
打印出左上方的x / y坐标和右下方的x / y坐标
编辑编号2 .:
刚刚花了几分钟,用我的测试工作簿完成了您的任务。这是万客隆:
Sub PositionDiagramm()
Dim x As Integer
Dim y As Integer
Dim height As Integer
Dim width As Integer
With Range(ActiveWindow.ActivePane.VisibleRange.AddressLocal)
x = .Left
y = .Top
width = .Width
height = .Height
End With
With ActiveSheet.Shapes("Diagramm 1")
.Top = y + ((height - .Height) / 2)
.Left = x + ((width - .Width) / 2)
End With
End Sub
Run Code Online (Sandbox Code Playgroud)