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!

How do I manipulate my current document in Word with VBS? 1

Status
Not open for further replies.

Dav136

Technical User
Oct 3, 2003
21
0
0
AT
I was thinking of something like...

Set wordobj = CreateObject("Word.Application")
wordobj.Activedocument.Selection.TypeText "Hello wordl"

I just get the message "This command is not available because there is no open document."

Any Help Appreciated!
Dav

(I'm new to VBS, and I dont want to use VBA for reasons)
 
You need to open the document prior to use.

Set wordobj = CreateObject("Word.Application")
wordobj.Open "c:\mydoc.doc"
wordobj.Activedocument.Selection.TypeText "Hello wordl"


________
George, M
 
Thanks!

However, I do not want to open a file from disk.

Is it possible to access a Document that is already opened for editing in Word?

Dav
 
I found this Example-Script, but still get an Error-Message "Object required: 'Selection'"

Anyone who can help??
Dav



How to access an active Word document with VBScript

The following code will add "Hello Word" to the active document. The style will be set to heading 1. The GetObject function will access a current instance of Word that is in memory. If there is no instance of Word in memory, you will get a runtime error.

Dim ObjWord
Const wdHeading1 = -2

Set ObjWord = GetObject(, "Word.Application")

ObjWord.Selection.Style = wdHeading1
ObjWord.Selection.TypeText "Hello Word"

Set ObjWord = Nothing
 
try this and see if it works
Dim worddoc
worddoc = createobject("word.basic")
worddoc.appshow
worddoc.filenew
worddoc.Insert "Hello World"
 
Try something like this:
Code:
Dim ObjWord,ObjSel
Const wdHeading1 = -2
Set ObjWord = GetObject(, "Word.Application")
Set ObjSel=ObjWord.Selection
ObjSel.Style = wdHeading1
ObjSel.TypeText "Hello Word"


Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top