Log in

View Full Version : Solved: Manipulating Word from Excel



jazzyt2u
08-27-2008, 05:48 PM
I have a few things I need assistance on.

1. I need to be able to copy a word from excel and then find a word in MS Word and replace that word with data from Excel.

It finds the word but doesn't replace it. Also the replacement word is a variable. So I don't know what to use for that in place of an actual word.


Sub ReplacingWordsInWord()
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open("H:\Test2\WordTestMacros.doc")
oWord.Visible = True
oWord.Selection.Find.ClearFormatting
oWord.Selection.Find.Replacement.ClearFormatting
With oWord.Selection.Find
.Text = "What"
.Replacement.Text = "Hearts"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oWord.Selection.Find.Execute Replace:=wdReplaceAll


2. I can't get into the header the following coding isn't working:

oWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader


3. Once I replace a word in MSWord how can I apply the header style. I'm having problems with the following code. It's generating a run-time error code 424 Object required. I defined the object with the coding above.



oWord.Selection.Style = ActiveDocument.Styles("Heading 1")
oWord.Selection.Font.Color = wdColorWhite
oWord.Selection.Font.Size = 8


Please help: pray2: