Pichon
08-26-2018, 05:55 PM
***UPDATE*** The problem persists, but it appears to have something to do with my Normal.dotm temple because if the Normal style is set to double spaced in normal.dotm, the it generates a double spaced document. If normal style is single spaced in normal.dotm, then it works properly. The other thing that I noticed is that the subroutine is changing the top margin from 1.5" to the default 1". This is super annoying.
I want to execute a find and replace in Word from an Excel subroutine.
I have a worksheet (variable name "stage") with 2 columns of data. Column A has values like <<FirstName>>, <<LastName>>, etc., and column B has values like James, Smith, etc.
My Word document has something like
Hello!
My First Name is: <<FirstName>>
My Last Name is: <<LastName>>
My document is single spaced, 12 pt, Times New Roman
I used this code:
For fieldRow = 2 To lastRow
tagName = stage.Cells(fieldRow, 1)
tagValue = stage.Cells(fieldRow, 2)
With wdDoc.Content.Find
.Text = tagName
.Replacement.Text = tagValue
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next fieldRow
This code cycles through the rows in the worksheet and finds the value in column A and replaces it with the value in column B for each row. That part works great. The problem is that the resulting document is double spaced, which I don't want.
Is there a way to preserve Word's formatting while executing this subroutine?
I want to execute a find and replace in Word from an Excel subroutine.
I have a worksheet (variable name "stage") with 2 columns of data. Column A has values like <<FirstName>>, <<LastName>>, etc., and column B has values like James, Smith, etc.
My Word document has something like
Hello!
My First Name is: <<FirstName>>
My Last Name is: <<LastName>>
My document is single spaced, 12 pt, Times New Roman
I used this code:
For fieldRow = 2 To lastRow
tagName = stage.Cells(fieldRow, 1)
tagValue = stage.Cells(fieldRow, 2)
With wdDoc.Content.Find
.Text = tagName
.Replacement.Text = tagValue
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next fieldRow
This code cycles through the rows in the worksheet and finds the value in column A and replaces it with the value in column B for each row. That part works great. The problem is that the resulting document is double spaced, which I don't want.
Is there a way to preserve Word's formatting while executing this subroutine?