在错误转到/如果没有错误如何跳过? [英] on error goto / if no error how to skip?

查看:87
本文介绍了在错误转到/如果没有错误如何跳过?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个具有电子邮件功能的程序,但是,某些计算机没有Outlook功能,因此我需要代码来打开错误的文件夹...所有这些我都在工作!但是...现在代码可以运行,即使没有错误也可以运行我的解决方法".参见代码.如果没有错误,我该如何跳过?

so i have a program that has an email function however, some of the computer dont have outlook and so i need the code to open a folder on error... All of that i have working! but... now the code runs and even if no error it will run my "workaround". See code. How do i skip if no error?

'NO OUTLOOK APP WORK AROUND
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

'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

End Sub

推荐答案

您可能想尝试一下

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

要获取有关错误处理的全面指南,请在此处.似乎您也在用户表单本身的代码中卸载了用户表单.在此处看看为什么这不是一个好主意在此处寻求指导

For a comprehensive guide of error handling have a look here. It also seems you unload a userform within the code of the userform itself. Have a look here why that is not a good idea and again look here for a guide

这篇关于在错误转到/如果没有错误如何跳过?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆