Mindlfurry
Technical User
I am fairly new to VBS but am pleased with the Outlook form I have created with one issue.
The script creates an Outlook form where a simple pull down menu is displayed along with an OK button. When selecting an entry from the pull down menu, I grab a previously saved email template where it gets displayed and can be easily updated and sent.
My problem is when I run the script a second time and simply close the window using the "X' in the upper right corner, the script continues to run, remembering the previously used case value, and proceeds to show an email message. I am trying to get the rotten thing to simply close after clicking the "X".
The Outlook user form (named UserForm1)is:
Private Sub CommandButton1_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Patching"
.AddItem "Emergency"
.AddItem "Troubleshooting"
.AddItem "Unplanned"
.AddItem "Test 5"
.AddItem "no change"
End With
End Sub
....The Outlook module is:
Public lstNum As Long
Public Sub ChooseTemplate()
Dim oMail As Outlook.MailItem
Dim strTemplate As String
Set oMail = Application.CreateItem(olMailItem)
UserForm1.Show
Select Case lstNum
Case -1
' -1 this is used if nothing is selected but the OK button is pressed
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\Nothing Picked.oft"
Case 0
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for patching.oft"
Case 1
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for emergency.oft"
Case 2
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for troubleshooting.oft"
Case 3
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for unplanned work.oft"
Case 4
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for testing.oft"
Case 5
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\Nothing Picked.oft"
End Select
Set oMail = Application.CreateItemFromTemplate(strTemplate)
oMail.Display
Set oMail = Nothing
End Sub
....any help would be greatly appreciated. I thought it wold be easy but I just need to clear the previous CASE selection value.
The script creates an Outlook form where a simple pull down menu is displayed along with an OK button. When selecting an entry from the pull down menu, I grab a previously saved email template where it gets displayed and can be easily updated and sent.
My problem is when I run the script a second time and simply close the window using the "X' in the upper right corner, the script continues to run, remembering the previously used case value, and proceeds to show an email message. I am trying to get the rotten thing to simply close after clicking the "X".
The Outlook user form (named UserForm1)is:
Private Sub CommandButton1_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Patching"
.AddItem "Emergency"
.AddItem "Troubleshooting"
.AddItem "Unplanned"
.AddItem "Test 5"
.AddItem "no change"
End With
End Sub
....The Outlook module is:
Public lstNum As Long
Public Sub ChooseTemplate()
Dim oMail As Outlook.MailItem
Dim strTemplate As String
Set oMail = Application.CreateItem(olMailItem)
UserForm1.Show
Select Case lstNum
Case -1
' -1 this is used if nothing is selected but the OK button is pressed
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\Nothing Picked.oft"
Case 0
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for patching.oft"
Case 1
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for emergency.oft"
Case 2
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for troubleshooting.oft"
Case 3
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for unplanned work.oft"
Case 4
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\System Outage for testing.oft"
Case 5
strTemplate = "C:\Users\Rob\AppData\Roaming\Microsoft\Templates\Nothing Picked.oft"
End Select
Set oMail = Application.CreateItemFromTemplate(strTemplate)
oMail.Display
Set oMail = Nothing
End Sub
....any help would be greatly appreciated. I thought it wold be easy but I just need to clear the previous CASE selection value.