![]() |
|
#5
|
|||
|
|||
|
Thank you Sir! The button I was referring to was the button on the form (continue button) which doesn't work, it does not automatically get the template and open it with the data entered. I amended the code but it still does not work. I cannot use the button and when I activate the macro from Outlook it gives me a VB error “Run-time error ‘13”: Type mismatch. When I press “Debug: it outlines the following code line in yellow: If .Tag = 0 Then I’m guessing the new code line needs a minor adjustment? Cheers I have amended the code to include the include what you mentioned, below is what I now have: Option Explicit Sub ReplaceFromUserForm() Dim olItem As MailItem Dim olEmail As Outlook.MailItem Dim olInsp As Outlook.Inspector Dim wdDoc As Object Dim oRng As Object Dim i As Long, j As Long Const sFindText As String = "#Name#|#Desc#|#Acres#|#Value#" Dim sReplaceText As String Dim vFind As Variant With UserForm1 .Caption = "Complete the fields" .CommandButton1.Caption = "Continue" .CommandButton2.Caption = "Cancel" .Show If .Tag = 0 Then GoTo lbl_Exit vFind = Split(sFindText, "|") Set olItem = CreateItemFromTemplate("U:\Operations Centre\Email Templates\form_test.oft") With olItem .BodyFormat = olFormatHTML Set olInsp = .GetInspector Set wdDoc = olInsp.WordEditor .Display For j = 0 To UBound(vFind) Set oRng = wdDoc.Range Select Case j Case 0 sReplaceText = UserForm1.TextBox1.Text Case 1 sReplaceText = UserForm1.TextBox2.Text Case 2 sReplaceText = UserForm1.TextBox3.Text Case 3 sReplaceText = UserForm1.TextBox4.Text Case Else End Select With oRng.Find Do While .Execute(findText:=vFind(j)) oRng.Text = sReplaceText oRng.collapse 0 DoEvents Loop End With Next j .Display End With End With Unload UserForm1 lbl_Exit: Exit Sub End Sub |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Show attachments as text in body of email??
|
thewiseguy31 | Outlook | 1 | 07-21-2015 09:07 PM |
move email based on text in email body
|
megatronixs | Outlook | 3 | 02-10-2015 10:58 AM |
| Finding specific text within body of email | Tammfran | Outlook | 0 | 03-14-2014 02:32 PM |
| add hyperlink in body of Outlook email | ChuckDrago | Word | 0 | 06-27-2013 01:13 PM |
| Outlook not sending body of email | sbertram | Outlook | 0 | 08-30-2012 11:50 AM |