1
Set olMessage = olApp.CreateItem(olMailItem)
olMessage.To = strEmailTo
olMessage.CC = strEmailCC
olMessage.Subject = strSubject
olMessage.Body = strBody
olMessage.Importance = olImportanceHigh
olMessage.Sensitivity = olConfidential
olMessage.Display ' Line With Error

上面的代码在我的用户表单上的一个按钮内。错误说

一个对话框打开。关闭它并重试

当我将任一代码单独放在宏中时,它可以正常工作并打开一封新电子邮件等,但是当我将宏设置为加载用户表单并将代码放在命令按钮下时,它会给出一个错误对话框:

Run-time error '2147467259 (80004005)'

A dialog box is open. Close it and try again.

Outlook 已打开,并且宏位于工具栏上。

模块 1(代码)

sub email() 
Load userform3
userform3.show
end sub

加载我的菜单很好

4

2 回答 2

2

If you are running this entirely from Outlook (and not using another application to automate the sending of an email, i.e., from Excel or PowerPoint, etc.) then this is the problem:

You are displaying your UserForm3 modally. This means that the application is essentially on hold, while the form is displayed.

To avoid this error, display it modelessly, like:

userform3.show vbModeless

Note: This allows the user to interact with the Outlook Application while the form is displayed. This may not be desired, in which case I think you will have to close/hide the userform before you display the email. Just add Unload Me preceding the .Display command:

Set olMessage = olApp.CreateItem(olMailItem)
olMessage.To = strEmailTo
olMessage.CC = strEmailCC
olMessage.Subject = strSubject
olMessage.Body = strBody
olMessage.Importance = olImportanceHigh
olMessage.Sensitivity = olConfidential
Unload Me
olMessage.Display ' Line With Error

Both above methods avoid the error. Which one you elect to use depends on your specific needs.

于 2013-08-20T16:01:10.993 回答
1

或者,您可以在执行代码之前简单地隐藏表单:

Private Sub cmdButton_Click()

UserForm3.hide

    Set olMessage = olApp.CreateItem(olMailItem)
    olMessage.To = strEmailTo
    olMessage.CC = strEmailCC
    olMessage.Subject = strSubject
    olMessage.Body = strBody
    olMessage.Importance = olImportanceHigh
    olMessage.Sensitivity = olConfidential
    olMessage.Display ' Line With Error

End Sub

隐藏用户窗体会绕过“打开对话框”错误并保留用户输入。它也比处理 VB 模式更简单,并且可以防止不需要的行为。

于 2013-11-19T23:06:19.620 回答