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

Converting Word Macro into VBScript 1

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
0
0
US
Hi all,

I have a Word macro that works quite nicely when run in Word. The catch is that I want to write into a VBScript that is run from the browser. This script opens Word, writes some stuff in it and then, I want it to run my little macro. I really want to write the macro in the script instead of just having the script call the macro. (Because other people will use the script and I can't run around installing the macro on everyone's machines.)

So, here is my macro. Any advice in getting into VBscript would help. (The := construction is a problem, as is aWord.)

Sub TestMacSpell()

ActiveDocument.Bookmarks.Add Name = "temp", Range = Selection.Range
For Each aWord In ActiveDocument.Words
If Not Application.CheckSpelling(aWord.Text, CustomDictionary = "CUSTOM.DIC", IgnoreUppercase:=False) Then
aWord.Font.Color = wdColorRed
End If
Next aWord
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
End Sub

Thanks,
Ann
 
I've gotten the := problem solved, but I am still hung up on the aWord part.

For some reason, aWord is not working at all, even though it works just fine when I paste it into a macro in Word and run it from there.

I've tried testing it several different ways and still no luck. (Yet everything I try still works in Word.)

Anyone have any idea what I missing here?

Thanks,
Ann
 
The blue code below is the VBScript equivalent of your VBA macro. One note - replace the oWord variable with whatever variable you use in your script to hold the reference to the Word.Application object.

The red code is what I used to emulate the functionality you describe as "This script opens Word, writes some stuff in it"

Set oWord = CreateObject("Word.Application")
WITH oWord
.Documents.Add
.ActiveDocument.BookMarks.Add "beginning", .Selection.Range
.Selection.TypeText "This is only a testff of the functionality."
.ActiveDocument.Bookmarks("beginning").Select
.ActiveDocument.Bookmarks("beginning").Delete
.Visible = True
END WITH


WITH oWord.ActiveDocument
.Bookmarks.Add "temp",oWord.Selection.Range
For Each aWord In .Words
If Not oWord.CheckSpelling(aWord.Text,"CUSTOM.DIC",False) Then
aWord.Font.Color = 255
End If
Next
.Bookmarks("temp").Select
.Bookmarks("temp").Delete
END WITH
Jon Hawkins
 
Brilliant. That worked perfectly.

Thanks so much.
Ann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top