Positioning objects in a word document

B

Brett Halligan

Hello there

ill cut strait to the chase.

I am trying to add, sequentially, objects to a word document. but when
I add these objects, tables in this example, it adds them to the top
of the document, If I use code like

{
strTemp = "Project" & vbTab & vbTab & rsExtras.Fields("Project
Name").Value & vbCrLf
strTemp = strTemp & "Job No" & vbTab & rsExtras.Fields("Job
Number").Value & vbCrLf
strTemp = = strTemp vbTab & "Created By" & vbTab &
rsExtras.Fields("Created By").Value & vbCrLf
strTemp = = strTemp vbTab & "Date Created" & vbTab &
rsExtras.Fields("Date Created").Value & vbCrLf

wrdAplication.ActiveDocument.Content =
wrdAplication.ActiveDocument.Content & strTemp

Set rTable = wrdAplication.ActiveDocument.Range(Start:=0, End:=0)
for intHloop = 1 To intHloop + 1
Set rTable = wrdAplication.ActiveDocument.Range(Start:=0,
End:=0)
wrdAplication.Selection.GoTo What:=wdGoToLine, Which:=wdGoToLast
wrdAplication.Selection.Tables.Add rTable, (lngCalculated
/ 10) + (intDistro + 5), (4 + intDatesPPage)
wrdAplication.Selection.GoTo What:=wdGoToLine,
Which:=wdGoToLast
next intHloop

}

The above code is only so I can get a feel for document object model,
I basically am trying to add a new table at the curser position, the
selection.goto method then moves the curser to the bottom of the page,
but when it inserts the next table it inserts the code at the top of
the page.

I am sure this is something really simple and I have just missed it in
my "hacked" together code.

Any help anyone could give would be great!

Thanks in advance and always, Kind regards

Brett Halligan
 
H

Helmut Weber

Hi Brett,
no to mention other ways of improvement,
the tables appear right where you place them
which is rTable with start:=0 end:=0, which is the
start of the document:
You may use selection.range instaed of rTable
plus have a look at these 2 examples:
---
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm
.Collapse direction:=wdCollapseEnd
.Tables.Add Range:=rDcm, numrows:=2, numcolumns:=4
End With
---
With Selection
.ExtendMode = False
.EndKey unit:=wdStory
.Tables.Add Range:=.Range, numrows:=2, numcolumns:=4
End With
 
B

Brett Halligan

Hi Brett,
no to mention other ways of improvement,
the tables appear right where you place them
which is rTable with start:=0 end:=0, which is the
start of the document:
You may use selection.range instaed of rTable
plus have a look at these 2 examples:
---
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm
.Collapse direction:=wdCollapseEnd
.Tables.Add Range:=rDcm, numrows:=2, numcolumns:=4
End With
---
With Selection
.ExtendMode = False
.EndKey unit:=wdStory
.Tables.Add Range:=.Range, numrows:=2, numcolumns:=4
End With
---
And there are many other ways.
Always a matter of personal preferences and style, too.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000

Fantastic!

I am working and in university tommorrow but ill have time to try it
out tommorrow night. You have helped me greatly!

thank you so much!

Brett Halligan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top