P
PaulC
I have a macro to open a word document from Excel 2003. I then need
replace text in the document with data from cells in a spreadsheet.
I open a version of word and then the spreadsheet as follows:
Sub ReplaceText()
Dim wdApp As Word.Application
dim ReplaceText as String
ReplaceText= Range("C2")
Set wdApp = CreateObject("word.application")
wdApp.Documents.Open("P:\WordDocument.doc").Application.Visible = True
With wdApp
..Visible = True
..WindowState = 1
With Selection.Find
..Text= "OAKNo"
..Replacement.Text = ReplaceText
..Forward = True
..Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End With
End Sub
This opens the word document but will not replace the text. However, I
can, for instance, add text to the document using:
Selection .TypeText Text:="text".
Also the replace code will run from within a subroutine in the word
document.
Any thoughts on why the replace code will not work, or another way to
do this would be very gratefully received.
Paul
replace text in the document with data from cells in a spreadsheet.
I open a version of word and then the spreadsheet as follows:
Sub ReplaceText()
Dim wdApp As Word.Application
dim ReplaceText as String
ReplaceText= Range("C2")
Set wdApp = CreateObject("word.application")
wdApp.Documents.Open("P:\WordDocument.doc").Application.Visible = True
With wdApp
..Visible = True
..WindowState = 1
With Selection.Find
..Text= "OAKNo"
..Replacement.Text = ReplaceText
..Forward = True
..Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End With
End Sub
This opens the word document but will not replace the text. However, I
can, for instance, add text to the document using:
Selection .TypeText Text:="text".
Also the replace code will run from within a subroutine in the word
document.
Any thoughts on why the replace code will not work, or another way to
do this would be very gratefully received.
Paul