Get Cell's position in word document

T

Tie Dan - Ìúµ°

Hi,

Assume there is a single cell (1 row 1 col) in a word document.
Then we typed lots of blank lines before it.

How can I get the cell's position, including x, y, cx, cy (mm)?

Thanks in advance,
TD
 
H

Helmut Weber

Hi Tie Dan,
select the cell and then try the following,
which will give you the position of the selection
on that page, not in the word document!
' wdVerticalPositionRelativeToPage = 6
' wdHorizontalPositionRelativeToPage = 5
Dim xPos As Single
Dim yPos As Single
xPos = Selection.Information(6)
yPos = Selection.Information(5)
xPos = PointsToCentimeters(xPos)
yPos = PointsToCentimeters(yPos)
MsgBox "x = " & xPos & " y = " & yPos
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
M

Mark Tangard

TD,

This will get the x and y. I don't know what cx and cy mean,
but maybe you can figure it out from here:

Dim t As Table, x As Single, y As Single
Set t = ActiveDocument.Tables(1)
With t.Rows
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
x = PointsToMillimeters(.HorizontalPosition)
y = PointsToMillimeters(.VerticalPosition)
End With
MsgBox "x = " & x & vbCr & "y = " & y
 
T

Tie Dan - ??

Hi Mark Tangard,

Thanks for your answer.

There is a table(1 row 1 col) in a word document.
I have tried the sample code you provided and got sample result x=176388.9
and y=0.
But its true position is about: HorizontalPosition=x=18,
VerticalPosition=y=6.5,width=cx=16, height=cy=5.5

Can you tell me more clearly how can I get table's position, including x, y,
cx, cy ?

Best Regards,
TD
 
M

Mark Tangard

TD,

The code works properly when I try it. I notice it behaves a bit
strangely sometimes if the table is in a frame. (But you shouldn't
need a frame to position a table in Word 2000 or above.)

To get width and height you can use:

cx = PointsToMillimeters(t.Cell(1,1).Width)
cy = PointsToMillimeters(t.Cell(1,1).Height)
 
K

Kumar

Hi,

I was also trying Mike's code for tables...I am getting the same
results as Tie Dan was getting. Infact I am getting the same x value
too, x=176388.9

I dont see a frame for the table..Mike/Tie Dan, if this was resolved
in your case, could you pls help me out too...

Thanks
Kamur
 

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