Outlook VBA 打开 Excel
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白了。我打开了另一本工作簿,然后在尝试打开第二个工作簿之前将其关闭,这会干扰它。为了解决这个问题,我保持 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.