Click a SUBMIT button to activate the coding

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am looking for some help in regards to using a "SUBMIT" button to activate the coding

this is the coding I presently have done:

Code:
Dim xRg As Range

Sub Worksheet_Change(ByVal Target As Range)
    Set xRg = Intersect(Range("F12"), Target)
    
    If Not (xRg Is Nothing) Then
        If Target = "yes" Or Target = "oui" Then
            Call Mail_emsg1
        End If
    End If
    
    Set xRg = Intersect(Range("J17"), Target)
    
    If Not (xRg Is Nothing) Then
        If Target = "Granted" Or Target = "Acquise" Then
            Call Mail_emsg2
        End If
    End If
    
    Set xRg = Intersect(Range("J17"), Target)
    
    If Not (xRg Is Nothing) Then
         If Target = "Pending" Or Target = "En Attente" Then
            Call Mail_emsg3
         End If
    End If
    
    Set xRg = Intersect(Range("H4"), Target)
    
    If Not (xRg Is Nothing) Then
         If Target = TargetValue Then
            Call Mail_emsg4
         End If
    End If
    
End Sub
Sub Mail_emsg1()
    Dim pNum As String
    Dim iName As String
    Dim vacancies As String
    Dim nIncumbent As String
    Dim excluded As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    
    pNum = Worksheets("Sheet1").Cells(6, "C").Value
    iName = Worksheets("Sheet1").Cells(10, "E").Value
    vacancie = Worksheets("Sheet1").Cells(12, "K").Value
    nIncumbent = Worksheets("Sheet1").Cells(15, "A").Value
    excluded = Worksheets("Sheet1").Cells(15, "F").Value
    
    
    xMailBody = "Hi Christine" & vbNewLine & vbNewLine & _
                "A 3811 has been submitted for approval that involves a position that is excluded or a person that is presently excluded" & vbNewLine & vbNewLine & _
                "Position number: " & pNum & vbNewLine & _
                "Incumbent's name: " & iName & vbNewLine & vbNewLine & _
                "Is the position presently vacant?: " & vacancie & vbNewLine & _
                "Name of present incumbent: " & nIncumbent & vbNewLine & _
                "Identify incumbent that will be excluded: " & excluded
                On Error Resume Next
    With xOutMail
        .To = "xxxxxxx[EMAIL="xxxxxxx@outlook.ca"]@outlook.ca[/EMAIL]"
        .CC = ""
        .BCC = ""
        .Subject = "send by cell value test"
        .Body = xMailBody
        .Display
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Sub Mail_emsg2()
    Dim pNum As String
    Dim iName As String
    Dim vacancies As String
    Dim nIncumbent As String
    Dim excluded As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    
    pNum = Worksheets("Sheet1").Cells(6, "C").Value
    iName = Worksheets("Sheet1").Cells(10, "E").Value
    StaffType = Worksheets("Sheet1").Cells(33, "C").Value
    Secreq = Worksheets("Sheet1").Cells(17, "D").Value
    PRI = Worksheets("Sheet1").Cells(10, "I").Value
    Location = Worksheets("Sheet1").Cells(10, "A").Value
    xMailBody = "Hi Security" & vbNewLine & vbNewLine & _
                "A staffing request has been submitted stating that security has ben obtained" & vbNewLine & _
                "Please reply with confirmation as to the status of the person's security clearance" & vbNewLine & vbNewLine & _
                "Position number: " & pNum & vbNewLine & _
                "Incumbent's name: " & iName & vbNewLine & _
                "PRI: " & PRI & vbNewLine & vbNewLine & _
                "Staffing Type: " & StaffType & vbNewLine & _
                "Security requirement of the position: " & Secreq & vbNewLine & _
                "Location: " & Location
                On Error Resume Next
    With xOutMail
        .To = "[EMAIL="xxxxxxx@outlook.ca"]xxxxxxx@outlook.ca[/EMAIL]"
        .CC = ""
        .BCC = ""
        .Subject = "Security clearance status - confirmation request "
        .Body = xMailBody
        .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Sub Mail_emsg3()
    Dim iName As String
    Dim vacancies As String
    Dim nIncumbent As String
    Dim excluded As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    
    
    iName = Worksheets("Sheet1").Cells(10, "E").Value
    StaffType = Worksheets("Sheet1").Cells(33, "C").Value
    Secreq = Worksheets("Sheet1").Cells(17, "D").Value
    PRI = Worksheets("Sheet1").Cells(10, "I").Value
    Location = Worksheets("Sheet1").Cells(10, "A").Value
    xMailBody = "Hi," & vbNewLine & vbNewLine & _
                "A staffing request has been submitted stating that security is Pending" & vbNewLine & _
                "Please use the appropriate link to access the desired security clearance" & vbNewLine & vbNewLine & _
                "Incumbent's name: " & iName & vbNewLine & _
                "PRI: " & PRI & vbNewLine & vbNewLine & _
                "Staffing Type: " & StaffType & vbNewLine & _
                "Security requirement of the position: " & Secreq & vbNewLine & _
                "Location: " & Location & vbNewLine & vbNewLine & _
                "Security Level - Reliability: [URL]http://publiservice.tbs-sct.gc.ca/tbsf-fsct/330-23-eng.asp[/URL] " & vbNewLine & _
                "Security Level - Secret: [URL]http://publiservice.tbs-sct.gc.ca/tbsf-fsct/330-60-eng.asp[/URL]"
                On Error Resume Next
    With xOutMail
        .To = "[EMAIL="xxxxxxx@outlook.ca"]xxxxxxx@outlook.ca[/EMAIL]"
        .CC = ""
        .BCC = ""
        .Subject = "Security Clearance Required - link to forms "
        .Body = xMailBody
        .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Sub Mail_emsg4()
    Dim EffStart As String
    Dim EffEnd As String
    Dim ClassReq As String
    Dim iName As String
    Dim pNum As String
    Dim Posrep As String
    Dim Bran As String
    Dim Sect As String
    Dim Reg As String
    Dim nIncumbent As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    
    
    EffStart = Worksheets("Sheet1").Cells(26, "K").Value
    EffEnd = Worksheets("Sheet1").Cells(27, "K").Value
    ClassReq = Worksheets("Sheet1").Cells(27, "D").Value
    iName = Worksheets("Sheet1").Cells(10, "E").Value
    pNum = Worksheets("Sheet1").Cells(6, "C").Value
    Posrep = Worksheets("Sheet1").Cells(26, "G").Value
    Bran = Worksheets("Sheet1").Cells(8, "A").Value
    Sect = Worksheets("Sheet1").Cells(8, "E").Value
    Reg = Worksheets("Sheet1").Cells(8, "I").Value
    Location = Worksheets("Sheet1").Cells(10, "A").Value
    
    xMailBody = "To Org. & Class.," & vbNewLine & vbNewLine & _
                "A Classification request has been submitted" & vbNewLine & _
                "Please refer to the information provided below" & vbNewLine & vbNewLine & _
                "Classification action requested: " & ClassReq & vbNewLine & vbNewLine & _
                "Incumbent's name (if applicable): " & iName & vbNewLine & _
                "Position number (if applicable): " & pNum & vbNewLine & _
                "Position number reports to: " & Posrep & vbNewLine & vbNewLine & _
                "Effective Start Date: " & EffStart & vbNewLine & _
                "End Date: " & EffEnd & vbNewLine & vbNewLine & _
                "Branch: " & Bran & vbNewLine & _
                "Section: " & Sect & vbNewLine & _
                "Region: " & Reg & vbNewLine & _
                "Location: " & Location
                On Error Resume Next
    With xOutMail
        .To = "xxxxxx[EMAIL="xxxxxx@outlook.ca"]@outlook.ca[/EMAIL]"
        .CC = ""
        .BCC = ""
        .Subject = "Classification Request"
        .Body = xMailBody
        .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

What I would like to happen is that once the client has completed the form, they click the SUBMIT button at the bottom of the form and it runs the coding on the sheet
 
Last edited by a moderator:
I can't get it to work using the checkbox but I replaced the functionality to insert an X and it now works

thank you for your help
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I can't get it to work using the checkbox but I replaced the functionality to insert an X and it now works

thank you for your help
You are welcome.

Yes, depending on the kind of object you are using, placing the checkbox in the cell doesn't necessarily bind the element to the cell.
The point of the MsgBox code was to see if it was doing that or not.

Glad you got it working.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top