Outlook Macro does run properly when sending excel attachment

whosphil

New Member
Joined
Feb 6, 2014
Messages
11
Hello all,

I created a userform for Outlook that populates an email based on what the user chooses and enters in userform1. This works fine when I create a new email, but when I choose an Excel File or any type of file and send to mail recipient the combobox draws a blank in userform1. How do I fix this?

Here's the code for userform1.

Code:
Option ExplicitPublic AlbanyLoad As Integer, CanastotaLoad As Integer, ChicopeeLoad As Integer, ColonieLoad As Integer
Public Body As String
Public ShipDate As Date






Private Sub LocationBox_Change()
Select Case LocationBox.Value
    Case "Albany"
        AlbanyLabel.Visible = True
        AlbanyLoadbox.Visible = True
        CanastotaLAbel.Visible = True
        CanastotaLoadBox.Visible = True
        ChicopeeLabel.Visible = True
        ChicopeeLoadBox.Visible = True
        ColonieLabel.Visible = True
        ColonieLoadBox.Visible = True
        ShipDateLabel.Visible = True
        ShipDateBox.Visible = True
    Case "Canastota"
        AlbanyLabel.Visible = False
        AlbanyLoadbox.Visible = False
        CanastotaLAbel.Visible = True
        CanastotaLoadBox.Visible = True
        ChicopeeLabel.Visible = False
        ChicopeeLoadBox.Visible = False
        ColonieLabel.Visible = False
        ColonieLoadBox.Visible = False
        ShipDateLabel.Visible = True
        ShipDateBox.Visible = True
    Case "Chicopee"
        AlbanyLabel.Visible = False
        AlbanyLoadbox.Visible = False
        CanastotaLAbel.Visible = False
        CanastotaLoadBox.Visible = False
        ChicopeeLabel.Visible = True
        ChicopeeLoadBox.Visible = True
        ColonieLabel.Visible = False
        ColonieLoadBox.Visible = False
        ShipDateLabel.Visible = True
        ShipDateBox.Visible = True
    Case "Colonie"
        AlbanyLabel.Visible = False
        AlbanyLoadbox.Visible = False
        CanastotaLAbel.Visible = False
        CanastotaLoadBox.Visible = False
        ChicopeeLabel.Visible = False
        ChicopeeLoadBox.Visible = False
        ColonieLabel.Visible = True
        ColonieLoadBox.Visible = True
        ShipDateLabel.Visible = True
        ShipDateBox.Visible = True
End Select
        
End Sub


Private Sub UserForm_Initialize()




With LocationBox
.AddItem "Chicopee"
.AddItem "Albany"
.AddItem "Colonie"
.AddItem "Canastota"
End With
End Sub




Private Sub CommandButton1_Click()
Dim oMail As Outlook.MailItem


ShipDate = Format(ShipDateBox.Value, "MM/DD/YY")


Body = "has been uploaded."


Set oMail = ActiveInspector.CurrentItem


Select Case LocationBox.Value


    Case "Albany"
        With oMail
            .To = "Albany Report"
            .Subject = "Albany " & ShipDate & " " & WeekdayName(Weekday(ShipDate)) & " Ship Uploaded"
            .Body = AlbanyLoadbox.Value & " Albany Loads" & vbLf & CanastotaLoadBox.Value & " Canastota Loads" & vbLf & ChicopeeLoadBox.Value & " Chicopee Loads" & vbLf & ColonieLoadBox.Value & " Colonie Loads" & vbLf & vbLf & "Phil"
            End With
    Case "Canastota"
        With oMail
            .To = "Canastota Report"
            .Subject = "Canastota " & ShipDate & " " & WeekdayName(Weekday(ShipDate)) & " Ship Uploaded"
            .Body = CanastotaLoadBox.Value & " Canastota Loads" & vbLf & vbLf & "Phil"
            End With
    Case "Chicopee"
        With oMail
            .To = "Chicopee Report"
            .Subject = "Chicopee " & ShipDate & " " & WeekdayName(Weekday(ShipDate)) & " Ship Uploaded"
            .Body = ChicopeeLoadBox.Value & " Chicopee Loads" & vbLf & vbLf & "Phil"
            End With
    Case "Colonie"
        With oMail
            .To = "Colonie Report"
            .Subject = "Colonie " & ShipDate & " " & WeekdayName(Weekday(ShipDate)) & " Ship Uploaded"
            .Body = ColonieLoadBox.Value & " Colonie Loads" & vbLf & vbLf & "Phil"
            End With
    End Select


Unload Me
oMail.Send




End Sub


and my module code..

Code:
Public Sub ReportEmails()UserForm1.Show
End Sub


Please let me know if you need more information. Thanks!
 

Forum statistics

Threads
1,226,884
Messages
6,193,502
Members
453,804
Latest member
Daniel OFlanagan

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