Outlook VBA 打开 excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5094624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Outlook VBA open excel
提问by loveforvdubs
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.
我正在尝试从 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
Again this code is running in outlook. I want to keep the file open once it opens.
此代码再次在 Outlook 中运行。我想在打开文件后保持打开状态。
回答by loveforvdubs
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.
我想通了。我正在打开一个不同的工作簿,然后在我尝试打开第二个工作簿之前关闭它,这会干扰它。为了解决这个问题,我保持 excel 应用程序打开并将工作簿对象重置为我想要的新工作簿。