所以我有一个具有电子邮件功能的程序,但是,某些计算机没有Outlook功能,因此我需要代码来打开错误的文件夹...所有这些我都在工作!但是...现在代码可以运行,即使没有错误也可以运行我的“解决方法”。参见代码。如果没有错误,我该如何跳过?
fail_safe
答案 0 :(得分:0)
您可能想尝试一下
On Error GoTo WORKAROUND
'Create Outlook email
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmailObj = xOutlookObj.CreateItem(0)
With xEmailObj
.Display
.To = ""
.CC = ""
.Subject = "QUOTE FOR -" + xSht.Name + xStr
.Attachments.Add xFolder
If DisplayEmail = False Then
'.Send
End If
End With
Else
MsgBox "The active worksheet cannot be blank"
Exit Sub
End If
' Seems this should always run
ActiveSheet.Name = "ACTUAL"
Unload Me
CLOSE1.Show
Exit Sub
'SKIP TO END OF WORKAROUND IF NO ERROR
WORKAROUND:
Dim PID As Double
Dim strRootPath As String
Const strExpExe = "explorer.exe"
Const strArg = " " '" /e,/root, "
'// Change rootpath here
strRootPath = "C:\Data Files"
PID = Shell(strExpExe & strArg & strRootPath, 3)
'THIS IS WHERE IT NEEDS TO PICK UP AGAIN.
ActiveSheet.Name = "ACTUAL"
Unload Me
CLOSE1.Show
有关错误处理的全面指南,请查看here。似乎您也在用户表单本身的代码中卸载了用户表单。看看here为什么不是一个好主意,然后再here寻求指导