Userform Browse button for File...Attached to Created Email

Qwest336

Board Regular
Joined
Jun 24, 2015
Messages
53
Good morning everyone,

I have one thing keeping this project from piloting. You would be my personal heros if you could help me out! Disclaimer: Novice to VBA who will be learning more in the coming months.

I have a Userform called "EscalationsForm". This userform has a Multipage object on it. Two of the multipage objects have buttons on them that I want to allow the user to Browse to a file and select it. I've used the following code to achieve that and to pass that filename as a string to a textbox so that the user can verify what they have attached:

Code:
Private Sub cmdUHAAttach_Click()
Dim fName As String
 fName = Application.GetOpenFilename()
 If Not fName = "False" Then
 tbUHADocAttached.Value = fName
 End If
End Sub

How can I take the file that is specified and attach it to an email that is created by the Click event of a Submit button? So far, I've tried the "Attachments.Add fName" under the "With Outmail" statement but I'm thinking since I declared fName as a String that I can't pass it. Do I need to declare it as an Object?

Any help in this is, again, greatly appreciated! I can't wait until I can answer questions like you all do!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Another one bites the dust!

After pulling my hair out, I finally found a site that put me on the path to solving it!

Final Coding was as follows:

Code:
Private Sub cmdUHAAttach_Click()
Dim strFilename As Variant
 
    ChDir "C:\" ' change to path to start dialog in
    
    strFilename = Application.GetOpenFilename(, , "Choose file for Escalation", , False)
    
    If TypeName(strFilename) = "String" Then
        tbUHADocAttached.Value = strFilename
    Else
        MsgBox "No attachment selected"
    End If
End Sub

Code:
Private Sub cmdRescAttach_Click()
Dim strFilename As Variant
 
    ChDir "C:\" ' change to path to start dialog in
    
    strFilename = Application.GetOpenFilename(, , "Choose file for Escalation", , False)
    
    If TypeName(strFilename) = "String" Then
        tbRescDocAttached.Value = strFilename
    Else
        MsgBox "No attachment selected"
    End If


 End Sub

In the "With Outmail" statement:
Code:
        .Attachments.Add EscalationsForm.tbRescDocAttached.Value & EscalationsForm.tbUHADocAttached.Value
        
    If tbRescDocAttached.Value <> "" Then
            .Attach tbRescDocAttached.Value
    ElseIf tbUHADocAttached.Value <> "" Then
            .Attach tbUHADocAttached.Value
    End If

2 (in my world) big ones solved in as many days! Feeling pretty good! Hopefully this helps another poor lost soul someday.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

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