Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to insert text in a new Word document?

Reply
 
Old 04-07-2009   #1 (permalink)
Don


 
 

How to insert text in a new Word document?


I am trying to generate a report (in Word) that contains text and tables.
What I am doing first is to write the title (objSelection.TypeText "Report")
and then
to generate a table.

The problem I have is that the table will overwrite the title so at the end
I will have only the table.

How I can avoid this?


Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()

Set objSelection = objWord.Selection
objSelection.TypeParagraph()

objSelection.Font.Name = "Times New Roman"
objSelection.Font.Size = "18"
objSelection.TypeText "Report"

Set objRange = objDoc.Range()

objDoc.Tables.Add objRange,1,5
Set objTable = objDoc.Tables(1)
objTable.Range.Font.Size = 10
objTable.Range.Style = "Medium Grid 1 - Accent 1"

objTable.Cell(x, 1).Range.Text = "h1"
objTable.Cell(x, 2).Range.text = "h2"
objTable.Cell(x, 3).Range.text = "h3"
objTable.Cell(x, 4).Range.text = "h4"
objTable.Cell(x, 5).Range.text = "h5"
…..



My System SpecsSystem Spec
Old 04-07-2009   #2 (permalink)
Don


 
 

RE: How to insert text in a new Word document?

Never mind...my fault.
I used
Set objRange = objDoc.Range()
instead of
Set objRange = objSelection.Range



"Don" wrote:
Quote:

>
> I am trying to generate a report (in Word) that contains text and tables.
> What I am doing first is to write the title (objSelection.TypeText "Report")
> and then
> to generate a table.
>
> The problem I have is that the table will overwrite the title so at the end
> I will have only the table.
>
> How I can avoid this?
>
>
> Set objWord = CreateObject("Word.Application")
> objWord.Visible = True
> Set objDoc = objWord.Documents.Add()
>
> Set objSelection = objWord.Selection
> objSelection.TypeParagraph()
>
> objSelection.Font.Name = "Times New Roman"
> objSelection.Font.Size = "18"
> objSelection.TypeText "Report"
>
> Set objRange = objDoc.Range()
>
> objDoc.Tables.Add objRange,1,5
> Set objTable = objDoc.Tables(1)
> objTable.Range.Font.Size = 10
> objTable.Range.Style = "Medium Grid 1 - Accent 1"
>
> objTable.Cell(x, 1).Range.Text = "h1"
> objTable.Cell(x, 2).Range.text = "h2"
> objTable.Cell(x, 3).Range.text = "h3"
> objTable.Cell(x, 4).Range.text = "h4"
> objTable.Cell(x, 5).Range.text = "h5"
> …..
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Converting Word 97-2003 document to Word 2007 Vista General
Send Word document by email from Word 2003 not working with WLM Live Mail
accidentally moved a MS Word document,now it dissapears everytime i open any word document Vista performance & maintenance
accidentally moved a MS Word document,now it dissapears everytime i open any word document Vista General
Creating Word document of Word 97-2003 file type on the New menu in Vista Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46