How can I prevent Excel from opening a userform when opened from a macro in Outlook?

删除回忆录丶 提交于 2019-12-24 05:40:24

问题


I am trying to create a macro in outlook that opens a file in excel and runs a procedure from that file. This code does that beautifully...

Dim ExApp As Excel.Application
Dim ExWbk As Workbook
Set ExApp = New Excel.Application
Set ExWbk = ExApp.Workbooks.Open("D:\Control Verification\Controls Verification Updated.xlsm")
ExApp.Visible = False

ExWbk.Application.Run "Module1.Email_All"

ExWbk.Close SaveChanges:=False

When someone opens this workbook normally I have a userform automatically display to allow the user to select different things, BUT when I open it from Outlook I don't want this userform to display.

I only need access to a different procedure in the userform that doesn't require any selections. Any ideas? Thanks.


回答1:


Work with Application.EnableEvents Property for disabling the Events before you open the workbook

Example

ExApp.EnableEvents = False 
ExApp.Workbooks.Open("Path") ' < Your code here
ExApp.EnableEvents = True


来源:https://stackoverflow.com/questions/50747275/how-can-i-prevent-excel-from-opening-a-userform-when-opened-from-a-macro-in-outl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!