Hello Forum,
This is a repost, originally asked in the Excel form. I believe this location may be more appropriate as it is geared toward outlook VBA behaviors.
---
Hello forum,
Using MS 2010 programs here.
Currently, I have a macro in excel that triggers from a user form to reach out to an outlook template, pull data from the user form and update the template. This is working perfectly, but I have multiple templates for certain scenarios.
I would like to determine how I could rewrite the formula to evaluate these scenarios in the user form and dictate the necessary template through one email template. So, rather than having six templates for the varied formats needed, I would have all 6 formats in one email template. The macro in excel would read certain fields to determine the correct scenario and after the email template is opened, delete the other 5 templates from the email.
I'm attempting to do this by creating the template variations in separate tables and hoping Excel/Outlook VBA can find these tables to delete the appropriate ones but having no luck.
Here is the current working code, values generalized for obvious reasons:
What I'd like is to have each table be referenced, so if circumstances dictate table 1 should be used - tables 2-6 are removed. The same for every other scenario.. scenario 3 appropriate 1-2/4-6 be deleted.
I've gotten as far as this:
Set atabl = myitem.table(1)
Select.atabl
Selection.Delete
[/CODE]
An alternative approach I thought might be to drop anchors like table1_start & table1_end, and write the code to select the contents between those two fields but finding nothing that works to do this in outlook.
Appreciate any help!
This is a repost, originally asked in the Excel form. I believe this location may be more appropriate as it is geared toward outlook VBA behaviors.
---
Hello forum,
Using MS 2010 programs here.
Currently, I have a macro in excel that triggers from a user form to reach out to an outlook template, pull data from the user form and update the template. This is working perfectly, but I have multiple templates for certain scenarios.
I would like to determine how I could rewrite the formula to evaluate these scenarios in the user form and dictate the necessary template through one email template. So, rather than having six templates for the varied formats needed, I would have all 6 formats in one email template. The macro in excel would read certain fields to determine the correct scenario and after the email template is opened, delete the other 5 templates from the email.
I'm attempting to do this by creating the template variations in separate tables and hoping Excel/Outlook VBA can find these tables to delete the appropriate ones but having no luck.
Here is the current working code, values generalized for obvious reasons:
Code:
Sub Email_1()
Application.ScreenUpdating = False
Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Dim oVal1 As String
Dim oVal2 As String
Dim oVal3 As String
Dim oVal4 As String
oVal1 = UserForm2.Controls("TextBox6").Value
oVal2 = UserForm2.Controls("TextBox2").Value
oVal3 = UserForm2.Controls("TextBox15").Value & ", " & UserForm2.Controls("TextBox16").Value
oVal4 = UserForm2.Controls("TextBox17").Value
Dim Hyperlink As Range
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate( _
"[URL="file://dtcnas-mnmi004/C_MTG_Groups/Default_Proj_Team/Change"]mydocuments\template[/URL].oft")
With MyItem
.CC = Replace(.CC, "dropval3", oVal3)
.CC = Replace(.CC, "dropval4", oVal4)
.Subject = Replace(.Subject, "dropval1", "This " & oVal1)
.Subject = Replace(.Subject, "dropval2", oVal2)
.HTMLBody = Replace(.HTMLBody, "Link", " & oVal1 & "> oVal1# " & oVal1& " - " & oVal2 & " ")
.Display
End With
Application.ScreenUpdating = True
End Sub
What I'd like is to have each table be referenced, so if circumstances dictate table 1 should be used - tables 2-6 are removed. The same for every other scenario.. scenario 3 appropriate 1-2/4-6 be deleted.
I've gotten as far as this:
Code:
...extending from previous code
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate( _
"mydocuments\template.oft")
With MyItem
Dim atabl As Outlook.Table
.Display
End With[
CODE]
However, I'm unable to find the right path to identify individual tables. Thinking it would look something like this, but it's not working...
Select.atabl
Selection.Delete
[/CODE]
An alternative approach I thought might be to drop anchors like table1_start & table1_end, and write the code to select the contents between those two fields but finding nothing that works to do this in outlook.
Appreciate any help!