Excel VBA:停止一段代码(正确) [英] Excel VBA: Stopping a section of code (correctly)

查看:80
本文介绍了Excel VBA:停止一段代码(正确)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在顶部检查此Exit Sub不会导致其他问题.它似乎可以正常工作,已添加到我的其余代码中以供参考.

Wanting to check this Exit Sub at the top isn't going to cause me other problems. It seems to work, added to rest of my code for reference.

到目前为止,到目前为止,建立文件扩展名"类型中的所有内容都有效.不确定仅显示下面的代码段是否足以回答该问题.

Everything from 'Establish File Extension type has worked to date/to this point. Unsure if just showing the below segment of code is sufficient to answer the question.

    If invalid > 0 Then mbResult = MsgBox("Something's missing. Please check and try again. There are " & invalid & " incomplete fields.", _
    vbOKOnly)

    Select Case mbResult
    Case vbOK
        Exit Sub
    End Select

    'Establish File Extension type
    With Destwb
        If Sourcewb.Name = .Name Then
            With Application
                .ScreenUpdating = True
                .EnableEvents = True
            End With
        End If
    End With

    FileExtStr = ".xlsm"
    FileFormatNum = 52

    'Save the new workbook and close it
    TempFilePath = ("www.mysharepoint.com") & "\"
    TempFileName = Range("A1").Text

    'Confirm Submission
    mbResult = MsgBox("This submission cannot be undone. Would you like to continue?", _
    vbYesNo)

    Select Case mbResult
    Case vbNo
        Exit Sub
    End Select

    'Build .SaveAs file Name based on variables established previously
    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    End With

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

    Application.DisplayAlerts = True
    ThisWorkbook.Activate

    'Display successful submission message
    MsgBox ("Thank you, your assessment has been successfully submitted.")

    ActiveSheet.Protect
End Sub

推荐答案

您可以更改以下行:

    If invalid > 0 Then mbResult = MsgBox("Something's missing. Please check and try again. There are " & invalid & " incomplete fields.", _
    vbOKOnly)

    Select Case mbResult
    Case vbOK
        Exit Sub
    End Selec

对此:

    If invalid > 0 Then
        MsgBox "Something's missing. Please check and try again. There are " & _
                invalid & " incomplete fields.", vbOKOnly
        Exit Sub
    End If

这篇关于Excel VBA:停止一段代码(正确)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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