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

automation with word; how to set tabs?

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi,
From my app I open an existing worddoc.
Once I've printed some items (from VFP by automation in Word) I'd like to do some tabsettings.

To so code I recorded a macro in Word.
Code:
macro recorde in Word
    Selection.ParagraphFormat.TabStops.ClearAll
    ActiveDocument.DefaultTabStop = CentimetersToPoints(1.25)
    Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(5), _
             Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Now I get stuck on how VFP-code for
ActiveDocument.DefaultTabStop = CentimetersToPoints(1.25)
Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(5)
and
Leader:=wdTabLeaderSpaces

Does someone know a white paper about these matters (apart from the great article of Tamar Granor

TIA
-Bart
 
Hi,

What is it you are after?
i. do some tab settings in the original Word Document
ii. print the original Word document in VFP as word document
iii. print the original Word document in VFP in a VFP.FRX

Regards,

Jockey(2)

P.S. Maybe Barabara's excellent WordTables.Zip will give you more info on this subject
 
Hi Jockey(2),

Thanks for your feedback

i I need different Tab-settings at different paragraphs
ii This, by automation? That's what I like to do but than I need to be able to do tabsettings programmaticly
iii My user wants a Worddoc as result

-Bart
 
Bart,

If you're stuck on CentimetersToPoints(), the fix is easy: Do the conversion yourself. The conversion factor is 28.35 (1 cm = 28.35 points).

So, instead of this:

Code:
ActiveDocument.DefaultTabStop = CentimetersToPoints(1.25)

You would have this:

Code:
loDoc.DefaultTabStop = 1.25 * 28.35

where loDoc is an object reference to the document.

If you're stuck on wdTabLeaderSpaces, just use 0 instead (or use 1 for dots, 2 for dashes). (In fact, you can probably ignore this parameter, as the spaces is the default.)

It's the same for wdAlignTabLeft. Either leave it out or use 0.

Does that answer your question?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike,
I figured out how to set a tab.
Code:
oDocument =oWord.Documents.Open(lcFileName)
*in case a new doc 
*oDocument = oWord.Documents.Add()

oRange = oDocument.Range()

WITH oDocument.Paragraphs.TabStops
  .ClearAll()
  .Add( oWord.CentimetersToPoints( 5 ) )
ENDWITH
But it's pretty difficult stuff.
So I tried to achieve my goal by adding a table i.s.o. to use tabs.
So in my code I included :
Code:
oWord.ActiveDocument.tables.add(oWord.Selection.Range,5,3)
loTable = oWord.ActiveDocument.tables(1)
loTable.cell(2,2).Range.InsertAfter("Hello World")

Quit surprising (for me) the table sits in the top of the worddoc now.
So another challenge to figure out how to locate the table at the disered location.

-Bart
 
Code:
oWord.ActiveDocument.tables.add(oWord.Selection.Range,5,3)
loTable = oWord.ActiveDocument.tables(1)
loTable.cell(2,2).Range.InsertAfter("Hello World")
Quit surprising (for me) the table sits in the top of the worddoc now.
So another challenge to figure out how to locate the table at the disered location.

Create a range variable that refers to the point where you want to put the table. Use that instead of oWord.Selection.Range. (In general. avoid the Selection object in Automation code. It just slows things down and is rarely needed.)

If, for example, you want the table at the current end of the document, try something like:

Code:
oRange = oWord.ActiveDocument.Range()
oRange = oRange.Collapse(0) 
* Now pass oRange to create the table
Tamar
 
oWord.ActiveDocument.tables.add(oWord.Selection.Range,5,3)
loTable = oWord.ActiveDocument.tables(1)
loTable.cell(2,2).Range.InsertAfter("Hello World")

Quit surprising (for me) the table sits in the top of the worddoc now.
So another challenge to figure out how to locate the table at the disered location.

Create a range variable that refers to the point where you want to put the table. Use that instead of oWord.Selection.Range. (In general. avoid the Selection object in Automation code. It just slows things down and is rarely needed.)

If, for example, you want the table at the current end of the document, try something like:

Code:
oRange = oWord.ActiveDocument.Range()
oRange = oRange.Collapse(0) 
* Now pass oRange to create the table
Tamar
 
Create a range variable that refers to the point where you want to put the table. Use that instead of oWord.Selection.Range. (In general. avoid the Selection object in Automation code. It just slows things down and is rarely needed.)

If, for example, you want the table at the current end of the document, try something like:

Code:
oRange = oWord.ActiveDocument.Range()
oRange = oRange.Collapse(0) 
* Now pass oRange to create the table
Tamar
 
Tamar,
Still some problems.

In the debugger I found that after:
oRange = oWord.ActiveDocument.Range()

oRange is still an object.

But after :
oRange = oRange.Collapse(0)
The debugger reports:
oRange = -

i.e. something goes wrong with the collapse(0)

any suggestion?

-Bart
 
My mistake. It should be just

Code:
oRange.Collapse(0)

rather than an assignment.

Tamar
 
Hi Tamar,
Thanks.
All works as expected now.
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top