Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2015, 06:14 PM
snickerbart snickerbart is offline Create a Userform in Outlook to select a macro for an email template. Windows 8 Create a Userform in Outlook to select a macro for an email template. Office 2010 64bit
Novice
Create a Userform in Outlook to select a macro for an email template.
 
Join Date: Apr 2015
Posts: 3
snickerbart is on a distinguished road
Default Create a Userform in Outlook to select a macro for an email template.

I have already created several macros that create an email Template. I am tryingto incorporate these into one UserForm that will allow me to select which email I want to send. However, when I test the macro, nothing is created? Am I missing some additional coding?

Private Sub CommandButton1_Click()
If OptionButton1 Then
Call QueueTrackingEmail 'Module 2
ElseIf OptionButton2 Then
Call DailyReportsEmail 'Module 3
ElseIf OptionButton3 Then
Call CaptureListingEmail 'Module 4
ElseIf OptionButton4 Then
Call EmmasEmail 'Module 5
ElseIf OptionButton5 Then
Call MondayAgingEmail 'Module 6
ElseIf OptionButton6 Then
Call Email672100 'Module 7


ElseIf OptionButton7 Then
Call Email672200 'Module 8
End If
End Sub

Thank you in advance for any advice on this matter.
Reply With Quote
  #2  
Old 04-08-2015, 10:46 PM
gmayor's Avatar
gmayor gmayor is offline Create a Userform in Outlook to select a macro for an email template. Windows 7 64bit Create a Userform in Outlook to select a macro for an email template. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

There is nothing in the form that would prevent it from working (though you should unload the form before ending the macro). You can test that by replacing the call statements with message boxes.

If the command button doesn't work correctly, then that reflects more on the individual macros called by the process, the nature of which we know nothing about.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-15-2015, 04:35 PM
snickerbart snickerbart is offline Create a Userform in Outlook to select a macro for an email template. Windows 8 Create a Userform in Outlook to select a macro for an email template. Office 2010 64bit
Novice
Create a Userform in Outlook to select a macro for an email template.
 
Join Date: Apr 2015
Posts: 3
snickerbart is on a distinguished road
Default

I've updated the code to reduce the script and included the code for the email macro so it can be tested by itself. The macro runs fine except no email is created.

Again, thank you for any advice on this.

Private Sub Email_Click()
End Sub
Private Sub CommandButton1_Click()
If OptionButton1 Then
MsgBox "OptionButton 1 was selected"
Call Email672200 ' Module 2
End If
If OptionButton2 Then
MsgBox "OptionButton 2 was selected"
'Sub Email672200()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "672200"
.CC = "672200 CC"
.BCC = ""
.Subject = "672200 - Escrow Shortage Account"
.HTMLBody = "Hello Everyone"
.Attachments.Add ""
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
'End Sub
End If
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Click()
End Sub
Reply With Quote
  #4  
Old 04-16-2015, 02:18 AM
gmayor's Avatar
gmayor gmayor is offline Create a Userform in Outlook to select a macro for an email template. Windows 7 64bit Create a Userform in Outlook to select a macro for an email template. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you are running the userform in Outlook, there is no need to create an Outlook application. You already have one and you are using it.

Code:
Option Explicit

Private Sub CommandButton1_Click()
    If Me.OptionButton1.Value = True Then
        Me.Hide
        MsgBox "OptionButton 1 was selected"
        Call Email672200        ' Module 2
    End If
    If Me.OptionButton2 Then
    Me.Hide
        MsgBox "OptionButton 2 was selected"
    End If
    Unload Me
End Sub
Sub Email672200()
Dim Outmail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
    Set Outmail = CreateItem(olMailItem)
    With Outmail
        .BodyFormat = olFormatHTML
        .To = "672200"
        .CC = "672200 CC"
        .BCC = ""
        '.Attachments.Add ""
        .Display
        .Subject = "672200 - Escrow Shortage Account"
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range(0, 0)
        oRng.Text = "Hello Everyone"
        
    End With
    On Error GoTo 0
    Set Outmail = Nothing
End Sub
Private Sub CommandButton2_Click()
    Unload Me
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 04-17-2015, 12:55 PM
snickerbart snickerbart is offline Create a Userform in Outlook to select a macro for an email template. Windows 8 Create a Userform in Outlook to select a macro for an email template. Office 2010 64bit
Novice
Create a Userform in Outlook to select a macro for an email template.
 
Join Date: Apr 2015
Posts: 3
snickerbart is on a distinguished road
Default

Thank you for that tip. I updated the code accordingly and the useform work great. I just needed a better pair of eyes to look at it.
Reply With Quote
Reply

Tags
radio button, templates, userform

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Userform in Outlook to select a macro for an email template. Agenda template - userform kennyD Word 4 04-07-2015 01:32 PM
Create a Userform in Outlook to select a macro for an email template. Create macro program to automatically email outlook with a visible cell range BillMaintenance Excel Programming 19 03-11-2015 03:19 PM
Create UserForm ComboBox or ContentControl ptmuldoon Word VBA 11 01-17-2015 05:58 PM
How to get Outlook 2007 userform into template? Royzer Outlook 0 04-13-2012 10:41 AM
Can't create new email or access email acounts Outlook 2003 onthebeaches Outlook 1 02-20-2012 10:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft