Current horizontal position cursor in Word document?

Q

qvadro

I insert table into Word document in any horizontal position cursor.
I use this code for creating table:

objWord.Selection.Tables.Add Range:=objWord.Selection.Range,
NumRows:=10, NumColumns:=5

Which function give me horizontal position cursor (Dim CursorPosition
As Long) in points or centimeters?
Then I can use this code for creating left indent for table:

objWord.Selection.Tables(1).Rows.LeftIndent =
CentimetersToPoints(CursorPosition)

Help me, please
 
D

Doug Robbins - Word MVP

Use

Dim CursorPosition As Long, i As Long
CursorPosition = Selection.Information(wdHorizontalPositionRelativeToPage)
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=10, NumColumns:=5
ActiveDocument.Tables(1).Rows.LeftIndent = CursorPosition
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.Tables(1).Columns(i).Width =
ActiveDocument.Tables(1).Columns(i).Width - CursorPosition /
ActiveDocument.Tables(1).Columns.Count
Next i

The For Next loop reduces the width of each column so that the table fits
within the margins

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
Q

qvadro

OK. Thank you.
Also I used this code for correct determining cursor position:

This code is important:
objWord.ActiveWindow.View.Type = wdNormalView

Then:

CursorPosition = objWord.Selection.Information(wdHorizontalPositionRelativeToPage)


objWord.Selection.Tables.Add Range:=objWord.Selection.Range,
NumRows:=1, NumColumns:=5

objWord.Selection.Tables(1).Rows.LeftIndent = CursorPosition


objWord.ActiveWindow.View.Type = wdPrintView
 
D

Doug Robbins - Word MVP

If you use

Selection.Information(wdHorizontalPositionRelativeToTextBoundary)

it doesn't matter what view you are in.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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