简体   繁体   English

使用左上方的链接单元格链接到Excel工作表

[英]Link to Excel Worksheet with Linked Cell in Upper Left

I am generating an Excell spreadsheet in a .NET application. 我正在.NET应用程序中生成Excell电子表格。 The file has two sheets. 该文件有两张纸。 The first is a cover sheet with deep links into the data, which is in the second sheet. 第一个是封面,其中包含到数据的深层链接,该封面在第二个表中。 When a link is clicked, the second sheet opens to that cell, with the position of the cell in the lower left corner. 单击链接时,第二个工作表打开到该单元格,该单元格的位置在左下角。 I need it to open with the cell in the upper right corner. 我需要用右上角的单元格打开它。

I'm pretty sure there is no way to make this happen in the .NET code that is generating the file. 我很确定没有办法在生成文件的.NET代码中实现此目的。 (But if I'm wrong, please tell me.) However, I did find some other discussions about this, and the solution seems to be to add a little but of VB code to the Excel file itself. (但是,如果我错了,请告诉我。)但是,我确实找到了有关此问题的其他讨论,解决方案似乎是在Excel文件本身中添加一些VB代码。 Meaning, to the template file that is used to seed the data and produce the final file. 意思是,模板文件用于种子数据并生成最终文件。

Here's the code: 这是代码:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    Application.Goto ActiveCell, True
End Sub

Thing is, I really don't know what to do with this code. 问题是,我真的不知道如何处理此代码。 I could benefit from some step-by-step instructions... like, assume I'm a total and complete idiot newbie when it comes to Excel (which actually, I am.) 我可以从一些分步说明中受益……例如,假设我是Excel的完全而又白痴的新手(实际上,我是。)

Thanks!! 谢谢!!

The following code will first go to the cell which is one column to the right of the target, placing it in the top left corner. 下面的代码将首先转到目标右侧一列的单元格,将其放在左上角。 It then shifts the window one page to the left, and then selects the original target again without scrolling. 然后,它将窗口向左移动一页,然后再次选择原始目标而不滚动。

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    Application.Goto ActiveCell.Offset(0, 1), True
    ActiveWindow.LargeScroll ToLeft:=1
    Application.Goto ActiveCell.Offset(0, -1), False
End Sub

I'm not sure what will happen if your target is, for instance, cell B100 - the window shift to the left may or may not work. 我不确定如果您的目标是单元格B100,将会发生什么情况-向左移动窗口可能会或可能不会起作用。

PS This code should be placed into the code module for the worksheet containing the hyperlinks. PS此代码应放置在包含超链接的工作表的代码模块中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM