Excel中心屏幕上的超链接单元格

我已经拿出了下面的macros,通过从一个表格到另一个表格的超链接,将屏幕居中在单元格上。 不幸的是,它还没有工作。 关于我在做什么错误的任何想法?

'Center screen to cell for map hyperlinks Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) 'On Error Resume Next Application.ScreenUpdating = False Dim onCell As Range Dim VisRows As Integer Dim VisCols As Integer Set onCell = Application.Evaluate(Target.SubAddress) onCell.Parent.Parent.Activate onCell.Parent.Activate With ActiveWindow.VisibleRange VisRows = .Rows.Count VisCols = .Columns.Count End With With Application .Goto Reference:=onCell.Parent.Cells( _ .WorksheetFunction.Max(1, onCell.Row + _ (onCell.Rows.Count / 2) - (VisRows / 2)), _ .WorksheetFunction.Max(1, onCell.Column + _ (onCell.Columns.Count / 2) - _ .WorksheetFunction.RoundDown((VisCols / 2), 0))), _ scroll:=True End With onCell.Select Application.ScreenUpdating = True End Sub 

请注意我的目标工作表中有隐藏的行和列,我不使用。

说我们的目标是点击一个超链接,作为结果跳转到另一个单元格,然后将新的ActiveCell放置在屏幕中间附近。 试试这个:

 Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) Application.Goto reference:=ActiveCell, scroll:=True With ActiveWindow i = .VisibleRange.Rows.Count / 2 j = .VisibleRange.Columns.Count / 2 .SmallScroll Up:=i, ToLeft:=j End With End Sub 

这取决于在跳转之后,活动窗口被设置在右下angular的目标处。 使用SmallScroll允许我们将窗口向下移动1/2,向右移动1/2。