+ Reply to Thread
Results 1 to 5 of 5

Connecting two macros

Hybrid View

  1. #1
    Registered User
    Join Date
    03-08-2007
    Posts
    24

    Connecting two macros

    Good day, I have two macros that are to run on one page. The first checks to ensure the required cells are filled in (RGACHECK), and the second (RGA_SEND) names/saves the file and emails to the appropriate individual.

    What I am hoping to achieve is if the first macro determines the cells are filled out, then it executes the second macro. If the cells are not filled out, the msg box states what cell(s) are empty and the user cannot proceed to the second macro until everything is filled out.

    
    Sub RGACHECK()
        Dim i As Range, j As Range, x As Range, y As Range
        Set i = Sheets("RGA FORM").Range("C7")
        Set j = Sheets("RGA FORM").Range("c8")
        Set x = Sheets("RGA FORM").Range("c9")
        Set y = Sheets("RGA FORM").Range("G9")
        Set k = Sheets("RGA FORM").Range("g10")
        Set l = Sheets("RGA FORM").Range("d16")
        
         
        If i.Value = "" Then
            i.Select
            GoTo cancelMe
        End If
         
        If j.Value = "" Then
            j.Select
            GoTo cancelMe
        End If
         
        If x.Value = "" Then
            x.Select
            GoTo cancelMe
        End If
         
        If y.Value = "" Then
            y.Select
            GoTo cancelMe
        End If
        
        If k.Value = "" Then
            k.Select
            GoTo cancelMe
        End If
         
        If l.Value = "" Then
            l.Select
            GoTo cancelMe
        End If
         
         
         
        Exit Sub
    cancelMe:
         MsgBox "Please fill in the ENTIRE FORM!" & ActiveCell.Address
        Cancel = True 'cancels the  save  event
         
    End Sub
    The second macro...

    
    Sub RGA_Send()
    'Jason
    
    Application.ScreenUpdating = False
    
    ActiveSheet.Unprotect Password:="2007jv2350"
    Cells.CheckSpelling SpellLang:=1033
    
    Dim fnb As String
    
    fnb = "RGA #09-" & Range("G2").Value & " " & Range("C7").Value & " " & Range("C8").Value & ".xls"
    
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\Jim Stevenson\My Documents\RGA Requests\" & fnb
      
        
       
    ActiveWorkbook.SendMail Array("safecracker@******.com", "jason@******.com")
        
    
    ActiveWorkbook.Close SaveChanges:=True
    
    ThisWorkbook.Close SaveChanges:=False
    
    Application.ScreenUpdating = False
    
    End Sub

    Both of the above macros work fine on their own, I am hoping someone here could help me connect the two macros.

    Thanks!

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Connecting two macros

    Before you exit the sub:
        Run "RGA_Send"
        Exit Sub
    cancelMe:
    This will call the other macro when your If statements don't branch to the Cancel: label

    Or you could just copy and paste the other code before the exit sub line in the first macro.

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Connecting two macros

    See if this does what you want:
    Sub RGACHECK()
    
    Dim r As Range
    
    Set r = Sheets("RGA FORM").Range("C7:C9,D16,G9:G10")
        
    If WorksheetFunction.CountA(r) < r.Count Then
        MsgBox "Please fill in the ENTIRE FORM!" & r.SpecialCells(xlCellTypeBlanks).Address
        Cancel = True 'cancels the  save  event
    Else
        RGA_Send
    End If
         
    End Sub

  4. #4
    Registered User
    Join Date
    03-08-2007
    Posts
    24

    Re: Connecting two macros

    Thanks for the quick replies! Palmetto, your solution worked perfect! Stephen, thanks for your input as well!

    I do have one additional question, on the second macro:

    
    Sub RGA_Send()
    'Jason
    
    Application.ScreenUpdating = False
    
    ActiveSheet.Unprotect Password:="2007jv2350"
    Cells.CheckSpelling SpellLang:=1033
    
    Dim fnb As String
    
    fnb = "RGA #09-" & Range("G2").Value & " " & Range("C7").Value & " " & Range("C8").Value & ".xls"
    
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\Jim Stevenson\My Documents\RGA Requests\" & fnb
      
        
       
    ActiveWorkbook.SendMail Array("safecracker@xxxxx.com", "jason@xxxxx.com")
        
    
    ActiveWorkbook.Close SaveChanges:=True
    
    ThisWorkbook.Close SaveChanges:=False
    
    Application.ScreenUpdating = False
    
    End Sub
    How would I have this file sent to an additional email address dependent upon a "YES" value in a specific cell (C11)?

    Thanks for all the assistance.

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Connecting two macros

    I would opt for a Select Case statement, but an IF statement would also work.
    Select Case Range("C11").Value
    
    Case Is = "Yes" 'email to the additional party
        ActiveWorkbook.SendMail Array("safecracker@xxxxx.com", "jason@xxxxx.com", "Yogi_Bear@yellowstonepark.com")
    
    Case Is = "No" 'email to original list
        ActiveWorkbook.SendMail Array("safecracker@xxxxx.com", "jason@xxxxx.com")
        
    Case Else 'optional line of code
        'whatever else your code should do
    
    End Select
    This bit of code above would replace your current line of code:
    ActiveWorkbook.SendMail Array("safecracker@xxxxx.com", "jason@xxxxx.com")

+ Reply to Thread

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