Hi,
I've got the code below, which creates a word document from a template and pastes certain cell values to text values in the template.
How would I go about the following - Sometimes the cell value for Telephone (in D2) would be "No telephone". How do I get the macro to instead of writing "No telephone" in the word document, to delete that line (i.e. send a 1 or 2 backspaces)?
Thanks!
I've got the code below, which creates a word document from a template and pastes certain cell values to text values in the template.
How would I go about the following - Sometimes the cell value for Telephone (in D2) would be "No telephone". How do I get the macro to instead of writing "No telephone" in the word document, to delete that line (i.e. send a 1 or 2 backspaces)?
Code:
[COLOR=#000000][FONT=Arial][SIZE=2]Sub SuitabilityLetter()[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]Worksheets("Fields").Activate[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]Dim wApp As Word.Application[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]Dim wDoc As Word.Document[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]Set wApp = CreateObject("Word.Application")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]wApp.DisplayAlerts = False[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]wApp.Visible = True[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]Set wDoc = wApp.Documents.Open("M:\...\template.doc", ReadOnly:=True)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]With wDoc[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Text = "[[Telephone]]"[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Execute[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Font.Size = 9[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection = Range("D2")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.EndOf[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Text = "[[Email]]"[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Execute[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Font.Size = 9[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection = Range("E2")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.EndOf[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Text = "[[Date]]"[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Execute[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Font.Size = 9[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection = Range("AD2")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.EndOf[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Text = "[[Salutation]]"[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Find.Execute[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.Font.Size = 9[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection = Range("A2")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] .Application.Selection.EndOf[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2] End With
[/SIZE][/FONT][/COLOR]
Thanks!
Last edited: