Run a VBA code after another VBA code

KlausW

Active Member
Joined
Sep 9, 2020
Messages
458
Office Version
  1. 2016
Platform
  1. Windows
Hi, I use this VBA code to send email with attached file, it works really well. I have set it to run a VBA code after but it doesn't do that, anyone who can help why it doesn't work.
Any help will be appreciated.
Best regards
Klaus W

VBA Code:
Sub Mail_workbook_Outlook()


    Dim OutApp As Object
    Dim OutMail As Object
    Dim sndEmail As String
    Dim toEmail As String
    Dim ccEmail As String
    Dim bccEmail As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
 

    On Error Resume Next
    With OutMail
        .To = Sheets("Stamdata").Range("j1").Value
        .CC = ""
        .BCC = ""
        .Subject = Sheets("Stamdata").Range("b1").Value
         .Body = Range("n1").Value & vbNewLine & vbNewLine & Range("n4").Value & vbNewLine & _
        Range("n5").Value & vbNewLine & Range("n6").Value & vbNewLine & Range("n7").Value & vbNewLine & _
        Range("n8").Value
        
        .Attachments.Add Range("I2") & Sheets("Stamdata").Range("B1").Value & ".pdf"  'attaches pdf file
        .Display                           '<-- .Display will show the email first for review
        '.Send                               '<-- .Send will auto send email without review
                                
    End With
    On Error GoTo 0


    Set OutMail = Nothing
    Set OutApp = Nothing
    
    Clear_All
    
End Sub

Sub Clear_All()

Dim Ws As Worksheet

For Each Ws In ActiveWorkbook.Worksheets
Ws.Range("A47:a55").ClearContents
Next Ws

DeleteAllPics

End Sub

Sub DeleteAllPics()
Dim Pic As Object
For Each Pic In ActiveSheet.Pictures
Sheets("Bilag").Select
Range("a1:a20").Select
Range("a1:a20").ClearContents
Pic.Delete
Next Pic
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Have you stepped through the VBa code (F8) to see if it goes there or just passes over?
 
Upvote 0
Have you stepped through the VBa code (F8) to see if it goes there or just passes over?
Hi thanks, I found the solution. I just had to switch around when the VBA code should start. Regards Klaus W have a nice day
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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