同时使用两个 VBE

发布于 2024-09-07 22:23:55 字数 252 浏览 2 评论 0原文

我刚刚接手了工作中一些非常可怕的遗留 vba 的维护工作。当我有空闲时间时,我基本上会在新模板中重组和重写它。有时,我会设法利用某种故障并同时打开两个不同的 VBE 实例。我不知道我到底做了什么来实现这一点,但这让我的生活变得更轻松,所以我想知道是否有其他人知道。我认为这与将 Word 作为新实例运行有关,但我无法更改工作电脑上的文件类型设置。

编辑:我通常复制并粘贴到 Excel 中并以这种方式执行此操作,但这并不理想,因为我还在工作的其他部分使用大量 Excel 宏

I've just taken over maintenance of some pretty scary legacy vba at work. When I have spare time I'm essentially restructuring and rewriting it in new templates. Every now and then, I've managed to exploit a glitch of sorts and have two different instances of the VBE open at once. I don't know exactly what I did to make this happen, but it makes my life much easier, so I'm wondering if anyone else knows. I assume it's something to do with running Word as a new instance, but I can't change my file type settings on my work PC.

Edit: I usually copy and paste into Excel and do it this way, but this is not ideal because I also use a lot of Excel macros for other parts of my job

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

祁梦 2024-09-14 22:23:55

您可以使用 Application.Run 在另一个 VBA 主机中执行代码,并且可以 VBE 执行代码。

Sub CallExcelUDFFromNonExcelHost()

  'Get an existing instance of Excel
  Dim appXL As Excel.Application
  Set appXL = GetObject(, "Excel.Application")

  'Get the already opened Excel workbook
  Dim wbk As Excel.Workbook
  Set wbk = appXL.Workbooks("MyExcelFunctions.xlsm")

  'Call the function in the Excel workbook
  Dim result
  result = appXL.Run(wbk.VBProject.Name & ".MyFunction", "Some Argument")

End Sub

You can use Application.Run to execute code in another VBA host, and you can step into the code across the VBEs.

Sub CallExcelUDFFromNonExcelHost()

  'Get an existing instance of Excel
  Dim appXL As Excel.Application
  Set appXL = GetObject(, "Excel.Application")

  'Get the already opened Excel workbook
  Dim wbk As Excel.Workbook
  Set wbk = appXL.Workbooks("MyExcelFunctions.xlsm")

  'Call the function in the Excel workbook
  Dim result
  result = appXL.Run(wbk.VBProject.Name & ".MyFunction", "Some Argument")

End Sub
忆沫 2024-09-14 22:23:55

尝试通过代码打开 Word:

Dim ws As Object

Set ws = CreateObject("word.application")
ws.Visible = True

您应该获得第二个实例。

Try opening Word through code:

Dim ws As Object

Set ws = CreateObject("word.application")
ws.Visible = True

You should get a second instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文