Need Help with Word Automation 
Author Message
 Need Help with Word Automation

Hello,

I am using Word Automation to make a table with the information I have in my
VB program.
I use the following function to do it.

However I would like to include some notes at the beginning of the table to
describe the table's content.
When I try to do so, it works but the text generated is overwritten by the
table.

I suppose I have to create another "Range" object but I dont know how to do
it.

Please help!

Public Sub PrintTable(titles As String, align As Variant, titre As String,
Optional oRS As ADODB.Recordset, Optional infos As String)
  On Error Resume Next

  Dim oDoc As Word.Document
  Dim oRange As Word.Range
  Dim sTemp As String
  Dim sFileName As String

  Set oDoc = WA.Documents.Add

  WA.Selection.Font.Name = "Arial"
  WA.Selection.Font.Size = 10

  Set oRange = oDoc.Range
  oRange.ParagraphFormat.Alignment = wdAlignParagraphRight
  If (IsMissing(infos) = True) Then
    sTemp = oRS.GetString(adClipString, -1, vbTab)
  Else
    sTemp = infos
  End If

  sTemp = titles & vbCrLf & sTemp
  oRange.Text = sTemp
  oRange.ConvertToTable vbTab, , , , wdTableFormatList4, AutoFit:=

  IncludePageNbr

  PrintDocument
  CloseDocument

End Sub



Sun, 21 Mar 2004 07:25:33 GMT  
 Need Help with Word Automation
Hi Fabien,

To avoid having to set another range, you could add the following statements
immediately before your PrintDocument statement. These statements position
the insertion point at the start of the document and then insert a note
before the table.

WA.Selection.HomeKey wdStory
WA.Selection.SplitTable
WA.Selection.InsertBefore "this is a note"

Make sure you position these statements AFTER the statement that creates the
table.

Bill Coan
Fill out letters, contracts, forms, in seconds! DataPrompter
prompts you for data, inserts it, updates it automatically.
Details at http://www.wordsite.com/DataPrompter.html

Quote:




Quote:
> Hello,

> I am using Word Automation to make a table with the information I have in
my
> VB program.
> I use the following function to do it.

> However I would like to include some notes at the beginning of the table
to
> describe the table's content.
> When I try to do so, it works but the text generated is overwritten by the
> table.

> I suppose I have to create another "Range" object but I dont know how to
do
> it.

> Please help!

> Public Sub PrintTable(titles As String, align As Variant, titre As String,
> Optional oRS As ADODB.Recordset, Optional infos As String)
>   On Error Resume Next

>   Dim oDoc As Word.Document
>   Dim oRange As Word.Range
>   Dim sTemp As String
>   Dim sFileName As String

>   Set oDoc = WA.Documents.Add

>   WA.Selection.Font.Name = "Arial"
>   WA.Selection.Font.Size = 10

>   Set oRange = oDoc.Range
>   oRange.ParagraphFormat.Alignment = wdAlignParagraphRight
>   If (IsMissing(infos) = True) Then
>     sTemp = oRS.GetString(adClipString, -1, vbTab)
>   Else
>     sTemp = infos
>   End If

>   sTemp = titles & vbCrLf & sTemp
>   oRange.Text = sTemp
>   oRange.ConvertToTable vbTab, , , , wdTableFormatList4, AutoFit:=

>   IncludePageNbr

Selection.HomeKey wdStory
Selection.SplitTable
Selection.InsertBefore "this is a test"

- Show quoted text -

Quote:
>   PrintDocument
>   CloseDocument

> End Sub



Sun, 21 Mar 2004 12:16:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Word/Access mail merge automation help needed

2. Access 97 to Word 8.0 Automation Help Needed

3. Need Help to Automation word through OLE.

4. Help needed w/Word and Access automation

5. Assistance needed! automation to set options in Word

6. Word automation needs admin

7. Automation w/WORD 97 - Simple example needed

8. help toggling bolding word by word needed

9. Help -- Background Print Word file using automation fails

10. HELP!____Access-word objects automation (office2000)

11. Help determing when Word Printout method has finished via Automation Server within vbscript

12. Word Automation Failure when other word documents are open

 

 
Powered by phpBB® Forum Software