Outlook VBA 打开 Excel

发布于 2024-10-19 04:20:10 字数 676 浏览 6 评论 0原文

我正在尝试从 Outlook 打开现有的 Excel 工作表。我可以看到工作簿打开,然后立即再次关闭。我将 Excel.Application 设置为可见。有什么想法吗?这是代码。

Function openNewForm(toDoSubject)
    MsgBox ("Called")
    Dim xlApp As Object
    Dim sourceWB As Workbook
    Dim sourceSH As Worksheet

    Set xlApp = CreateObject("Excel.Application")

    With xlApp
        .Visible = True
        .EnableEvents = False
    End With


    strFile = "C:\Users\Peter\Documents\ASI\OrderSystem\NewOrderSheet.xlsm"

    Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
    Set sourceSH = sourceWB.Worksheets("OrderForm")
    sourceWB.Activate
End Function

这段代码再次在 Outlook 中运行。我想在文件打开后保持打开状态。

I am trying to open an existing excel sheet from outlook. I can see the workbook open and then it imediately closes again. I have the Excel.Application set to visible. Any ideas? Here is the code.

Function openNewForm(toDoSubject)
    MsgBox ("Called")
    Dim xlApp As Object
    Dim sourceWB As Workbook
    Dim sourceSH As Worksheet

    Set xlApp = CreateObject("Excel.Application")

    With xlApp
        .Visible = True
        .EnableEvents = False
    End With


    strFile = "C:\Users\Peter\Documents\ASI\OrderSystem\NewOrderSheet.xlsm"

    Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
    Set sourceSH = sourceWB.Worksheets("OrderForm")
    sourceWB.Activate
End Function

Again this code is running in outlook. I want to keep the file open once it opens.

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

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

发布评论

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

评论(1

热血少△年 2024-10-26 04:20:10

我明白了。我打开了另一本工作簿,然后在尝试打开第二个工作簿之前将其关闭,这会干扰它。为了解决这个问题,我保持 Excel 应用程序打开并将工作簿对象重置为我想要的新工作簿。

I got it figured out. I was opening a different workbook and then closing it before I try to open the second one and that was interfering with it. To fix this I kept the excel app open and reset the workbook object to the new workbook i wanted.

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