简体   繁体   English

如何在不使用Workbook_Open的情况下在特定行上打开工作簿?

[英]How to open workbook on a certain row without using Workbook_Open?

I have a working macro that creates a new workbook, writes to it, and emails it to a client. 我有一个工作宏,可以创建一个新工作簿,对其进行写入,然后通过电子邮件将其发送给客户端。

The workbook opens on the first row of the workbook, and the client needs to scroll down to find the data they need. 该工作簿在工作簿的第一行上打开,并且客户端需要向下滚动以查找所需的数据。 I would like the Excel file to open in the middle row of the file. 我希望在文件的中间行中打开Excel文件。

The workbook cannot contain macros due to security reasons. 由于安全原因,该工作簿不能包含宏。 Thus writing code on the Workbook_Open() method to go to a certain row is not feasible. 因此,在Workbook_Open()方法上编写代码以转到特定行是不可行的。

If you have your VBA code select a given Range and make it visible on screen prior to sending, it should be the selected range and visible when opening directly from the attachment. 如果您具有VBA代码,请选择给定的Range并在发送之前使其在屏幕上可见,则该范围应该是所选范围,并且在直接从附件中打开时可见。 As intended in the OP, you do not need your workbook to contain any VBA code. 按照OP的要求,您不需要工作簿包含任何VBA代码。

I did this with the code below to create the workbook Then I manually selected Send by email (it should be irrelevant if this is done via VBA), sent it to myself, and opened it from the attachment. 我使用下面的代码创建了工作簿,然后手动选择了“ 通过电子邮件发送” (如果通过VBA完成,则应该无关紧要),将其发送给自己,然后从附件中打开它。

Sub create_wb_select_range()
    Dim wb As Workbook
    Set wb = Workbooks.Add
    Dim ws As Worksheet
    Set ws = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count))
    Dim wsname As String
    wsname = "MySheet"
    ws.Name = wsname
    Dim rngname As String
    rngname = "J68"
    ws.Range(rngname).Select
End Sub

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

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