Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.word.vba.general,microsoft.public.office.developer.automation
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

  #2   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.word.vba.general,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 23
Default Excel running Word macro

You should be able to make use of the built in \line bookmark

Try

Dim delrange as Range
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="XXPAEDT", Wrap:=wdFindContinue,
Forward:=True) = True
Set delrange = Selection.Bookmarks("\line).Range
delrange.Delete
'the selection will now have moved to the following line, which is
also to be deleted so repeat the process
Set delrange = Selection.Bookmarks("\line).Range
delrange.Delete Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"rsphorler" wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.word.vba.general,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 2
Default Excel running Word macro

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


If you have Word open more than one document at a time, it is best to assign
each document to a document variable so that you can later distinguish which
document you want to apply your macro.
Dim objDoc1 as Word.Document
Dim objDoc2 as Word.Document
....

Set objDoc1 = Documents.Open ....
....
Set objDoc2 = Documents.Open ....
....
objDoc1.Activate
....run code on objDoc1
objDoc2.Activate
....run code on objDoc2
....
Set objDoc1 = Nothing
Set objDoc2 = Nothing

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


--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Macro running another macro inside K1KKKA Excel Discussion (Misc queries) 1 December 20th 06 08:21 PM
disable user running macro from Tools Macro Steve Simons Excel Discussion (Misc queries) 4 September 28th 06 06:28 AM
Running a Macro automatically from Excel Brakeshoe Excel Worksheet Functions 1 July 13th 05 11:23 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
Macro - Open Word with Excel macro Bill Excel Discussion (Misc queries) 3 May 23rd 05 11:21 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"