Outlook VBA打开excel [英] Outlook VBA open excel

查看:588
本文介绍了Outlook VBA打开excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图从展望中打开现有的Excel表。我可以看到工作簿打开,然后再次关闭。我将Excel.Application设置为可见。有任何想法吗?这是代码。

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

此代码再次运行在Outlook中。我打开文件后打开文件。

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

推荐答案

我知道了。我正在打开一个不同的工作簿,然后关闭它,然后我尝试打开第二个,这是干扰它。为了解决这个问题,我保持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.

这篇关于Outlook VBA打开excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆