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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Word Automation through an ASP VBScript Page

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
US
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.
 
the Selection.Find.Execute function has ALOT more parameters than 3, but most are optional hence the use of :=

if you don't want to do that, then you have to put blank spaces for the parameters you are not using.

based on the help file for Find.Execute, I think you need to use this

Find.Execute "@@@", , , , , , , , "^|", wdReplaceAll
 
Unfortunately, that didn't work.
I have also tried this construction:
app.Selection.Find.Execute "@@@", False, False, False, False, False, True, wdFindContinue, False, "^l", wdReplaceAll

But still, the Word document just has the last instance of @@@ highlighted (evidence that it did the find, but didn't execute the replace).

Am I missing something here?
 
I created a button in word and this code worked in selecting the whole document and changing everythingd

Code:
Selection.WholeStory
Selection.Find.Execute "@@@", , , , , , , , , "222", wdReplaceAll

-Christian
 
You are aware that Microsoft strongly recommends you not use Office servers (Word, Excel) on the server-side this way, right?

Performance issues, hangs on dialogs, and random blowups, from the sound of it:

"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when run in this environment."

See
 
I'm not using office on the server-side. I tried using Office on the server-side, had it working, and then it got messed up when a service pack was installed.

The script I have now is entirely client-side. All my script does is load my data into an array, open Word on the client machine, write the data into Word a line at a time, format the data into a table and then do the find and replace. It works great, with the specifications for the find and replace listed in this post.

I also have a different script that puts data into Excel. No problems, as long as the script is entirely client-side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top