Adding attachment to form to be emailed

Beechy

New Member
Joined
Aug 4, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

First post here, I'm learning how to use VBA. I have currently got a code that allows me to click a button and the form will be emailed to an inbox. What I'd like to add is to be able to add any supporting attachments before sending so it comes on the mail. I've read on a getFile code but not sure how to add this in to the below, appreciate any help!

VBA Code:
Private Sub CommandButton1_Click()

    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range

    On Error GoTo StopMacro

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

     Set Sendrng = Worksheets("Sheet1").Range("B2:F25")
     

     Set AWorksheet = ActiveSheet

     With Sendrng
    .Parent.Select
    Set rng = ActiveCell
     .Select
      ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope
            With .Item
                .To = ""
                .CC = ""
                .BCC = ""
                .Subject = Worksheets("Sheet1").Range("C1")
                .Send
            End With

        End With
              rng.Select
    End With

        AWorksheet.Select

Sheet1.Activate
Range("c2:c3").ClearContents
Range("e2:e3").ClearContents
Range("c5") = ""
Range("B8:b10").ClearContents
Range("c8:c10").ClearContents
Range("d8:d10").ClearContents
Range("e8:e10").ClearContents
Range("f8:f10").ClearContents
Range("g8:g10").ClearContents
Range("b13") = ""



StopMacro:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False
 
 MsgBox "Manaul RV form has been submitted to the RV inbox", , "Submitted"
   Application.DisplayAlerts = False

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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