View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.word.vba.general,microsoft.public.office.developer.automation
rsphorler rsphorler is offline
external usenet poster
 
Posts: 6
Default Excel running Word macro

I have a complicated macro which does several things to a series of
imported htm files, however it is not working as expected.

An excel macro produces a list of htm files within a directory and
outputs it to sheet1 and then one by one uses this as a parameter to
start a word macro (ww has been defined as the word application
object)

ww.Documents.Open ThisWorkbook.Path & "\datastage1.doc"
runnow = ww.Run("stage1", file)

This runs the macro stage1 in the word document datastage1.doc using
the file stored in variable "file".

Sub stage1(myfile As String)
file = myfile
folderpath = ActiveDocument.Path & "\inputhtm\"
Documents.Open FileName:=folderpath & file

This word macro then opens the file and is meant to remove all
occurences of a two line text fragment using a word (XXPAEDT) to find
the first of those lines:

'DELETE UNWANTED LINES
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="XXPAEDT", Wrap:=wdFindContinue,
Forward:=True) = True
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Loop
End With

This does not work and the lines are not removed, yet if i open the
document manualy and then use the macro after removing the above
section that opens the htm file (so it starts with the remove unwanted
lines comment) it works perfectly!!!

Any ideas as to why the different behaviour if the file is opened
manually by the user or automatically by the macro

Thanks

Richard