Results 1 to 4 of 4

Code to end a main sub before end sub point

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-24-2009
    Location
    SCOTLAND
    MS-Off Ver
    Excel Version 2308
    Posts
    151

    Code to end a main sub before end sub point

    I’m using this code to run consecutive programs, which works really well, apart from one little glitch.

    Public Sub main()
    Call Sendmail
    Call saveaspdfwithdate2
    End Sub
    The problem is that during the Sendmail sub if I select No on the vb, the program continues onto the next sub which unfortunately clears the data I have input to cells on the worksheet (as it should do).

    I therefore need a piece of code which will end the main sub at this point, if No is selected, without running the saveaspdfwithdate2 coding.
    Here is the coding for Sendmail

    Sub Sendmail()
    Dim objOutlook, objMsg, objNameSpace, opjFolder, strOutput, strSubject, StrTo, StrMsg
    Dim ans
    ans = MsgBox("Do you wish to save this System Register?", vbYesNo)
    If ans = vbYes Then
      'Continue
    Else: Exit Sub
    End If
    StrTo = "joebloggs@123l.com"
    StrMsg = InputBox("Name the Register ready for approval")
    Const olMailItem = 0
    Set objOutlook = CreateObject("Outlook.application")
    Set objNameSpace = objOutlook.GetNameSpace("MAPI")
    Set objMsg = objOutlook.CreateItem(olMailItem)
    objMsg.To = StrTo
    objMsg.Display
    objMsg.Subject = "Register Added To Folder"
    objMsg.Body = StrMsg
    Set objFolder = Nothing
    Set objNameSpace = Nothing
    Set objOutlook = Nothing
    Set ss = CreateObject("WScript.Shell")
    Set ss = Nothing
    End Sub
    Last edited by heliskier89; 07-12-2009 at 02:04 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1