Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting VBScript to Execute Properly in the Browser (Word Automation) 1

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
US
Please help. I am losing hair and sleep over this problem.

I have a VBScript that I want to execute inside the browser (IE). The Script opens Word, inserts text, formats the text into a table. The last thing I need the script to do is search for @@@ and replace it with ^l (manual line break).

I have a routine set up that should locate all instances of @@@. I can see that it is moving through the text, but it's not executing the Replace.

My current code looks like this:

app.Selection.WholeStory
app.ActiveDocument.Range.ConvertToTable Separator=wdSeparateByTabs

app.Selection.WholeStory

Do

app.Selection.Find.ClearFormatting
app.Selection.Find.Replacement.ClearFormatting
app.Selection.Find.Text = "@@@"
app.Selection.Find.Replacement.Text = "^l"
app.Selection.Find.Forward = True
app.Selection.Find.Wrap = True
app.Selection.Find.Format = False
app.Selection.Find.MatchCase = False
app.Selection.Find.MatchWholeWord = False
app.Selection.Find.MatchWildcards = False
app.Selection.Find.MatchSoundsLike = False
app.Selection.Find.MatchAllWordForms = False
app.Selection.Find.Replace = wdReplaceAll
app.Selection.Find.Execute "@@@", "^l", wdReplaceAll
If app.Selection.Find.Execute = False Then Exit Do
Loop


I cobbled this code together by recording a macro and then playing with the results. One of the problems I am having is that the macro uses code like this:
Selection.Find.Execute Replace:=wdReplaceAll

The browser really does not like the := construction.

Can someone tell me how to get the replace to execute without using :=?

Thanks,
Ann
 
Hello, Scanlan.

There are indeed a bit of trial-and-error there to port between vba and vbs as office obj models are immense!

Here is the script centered on your job in hand. I follow your script to the closest possible.

regards - tsuji

'----------------------------------
Set app = CreateObject("Word.Application")
app.Visible=True
app.Documents.Open("yourfile.doc") 'Edit this
app.Selection.WholeStory
app.Selection.Find.ClearFormatting
app.Selection.Find.Replacement.ClearFormatting

With app.Selection.Find
.Text = "@@@"
.Replacement.Text = "^l"
.Forward = True
.Wrap = False
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
'''''' .Replace = 2 'wdReplaceAll = 2, ".Replace" not supported
End With

app.Selection.Find.Execute ,,,,,,,,,,2

app.Documents.Save
app.Documents.Close
app.Quit

Set app = Nothing
'----------------------------------
 
Thank you so much! That worked perfectly. I am so thrilled. On to putting that code into all of my pages. Hooray.

Thanks,
Scanlan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top