Outlook VBA打开excel [英] Outlook VBA open 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屋!