简体   繁体   English

Excel / VBA:在新窗口中打开新工作簿

[英]Excel/VBA: Open New Workbook In New Window

I am using Excel 2010, and am looking for a VBA script that will open a new workbook in a new window (such that I could, for example, place one workbook on each of 2 monitors). 我正在使用Excel 2010,并且正在寻找一个VBA脚本,该脚本将在新窗口中打开一个新工作簿(例如,我可以将一个工作簿放在2个监视器上)。

I'd then place this VBA/macro on the ribbon and assign it a shortcut key. 然后,我将此VBA /宏放在功能区上并为其分配快捷键。 Thus, it'd work like CTRL+N, but the new workbook would open in a separate window/instance of Excel, instead of the same. 因此,它的工作方式类似于CTRL + N,但是新工作簿将在单独的Excel窗口/实例中打开,而不是在同一窗口中打开。

I've tried just using Shell ("excel.exe"), but I suppose since it is running from my PERSONAL.XLSB workbook, it then asks if I want to Read Only or Notify. 我已经尝试过仅使用Shell(“ excel.exe”),但是我想由于它是从我的PERSONAL.XLSB工作簿运行的,因此它询问我是只读还是通知。

I just want CTRL+N functionality, but with the new window addition. 我只需要CTRL + N功能,但要添加新窗口。

Thank you! 谢谢!

Alternate way to do the same thing, includes selecting the file you want to open: 另一种执行相同操作的方法,包括选择要打开的文件:

Sub tgr()

    Dim strFilePath As String
    Dim xlApp As Object

    strFilePath = Application.GetOpenFilename("Excel Files, *.xls*")
    If strFilePath = "False" Then Exit Sub  'Pressed cancel

    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    xlApp.Workbooks.Open strFilePath

End Sub

You can use this: 您可以使用此:

Sub NewApp()
    With CreateObject("Excel.Application")
        .Workbooks.Add
        .Visible = True
    End With
End Sub

but be aware that any automation of this sort won't load startup workbooks and add-ins by default. 但是请注意,默认情况下,任何此类自动化操作都不会加载启动工作簿和加载项。

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

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