Cursor Position in Textcolumns

A

Ashish

Hi,

I have looked wherever I can but I just can't find a reliable way of
checking which textcolumn am I, in the code.
I have tried the Information(wdHorizontalPositionRelativeToPage),which
unforunately just about anywhere gives me a -1, no reason at all.
EVEN WHEN I HAVE ONLY A SINGLE LINE selected. 100% zoom in page view is the
default.
Next try has been the distancefromright and left in the hope of getting the
position wrt to the page end. No help again.

Is there a reliable way of knowing the current textcolumn of the
cell/range/row/selection/insertion point?

Ohh: I have 2 textcols, filled with a table. I am interating through the
rows. I need to do something specific for each row in the second text column.
I just can't triangulate the poistion. Each row may have a variable number of
cells.

Please help if someone has seen something like this.
Thanks.
 
K

Klaus Linke

Hi Ashish,

You can get it from the dialog:
Dialogs(wdDialogFormatColumns).ColumnNo

Would be nice if the ".Information" property would return it, too. Getting stuff from dialogs was the usual way to get information in old versions, but it's a dying art.

Greetings,
Klaus
 
A

Ashish Dutt Sharma

Klaus,

Thanks for the tip. I am experimenting with it. However, is there a place
where they tell how does this work. Specifically, which dialogs property am I
retrieving? Reason for my question is this :
My document is all tables.
3-4 rows on top are single colum(Headers)
Then the main text of the doc is in the table populated inside the text col.
I am selecting the entire document. Now i need to do, lets say, process A
for the header rows, process B for the rows in first text col and C for the
one in second col.
Currently I'm iterating through all rows of all tables in the selection.
When I get to the rows in the textcols, I need to find what text col am I in
to apply B or C. My current loop actually is:

For Each myTable In Selection.Tables
For Each myRow In myTable.Rows
counter = counter + 1
If counter < 4 Then GoTo NextRow
If Dialogs(wdDialogFormatColumns).ColumnNo = 1 Then
Call fixLeft(myRow.Range)
Else
Call fixRight(myRow.Range)
End If
NextRow:
Next
Next
End Sub

Basically, the first 4 rows have been taken care of already. Earlier I was
trying the Information property at the check point. But it was entirely
random replies.
 
K

Klaus Linke

Hi Ashish,
However, is there a place where they tell how does this work.
Specifically, which dialogs property am I retrieving?

The VBA help has a page on arguments of built-in dialogs.
You might find more info in the old Word95 WordBasic help file from
http://www.microsoft.com/downloads/...FamilyID=1A24B2A7-31AE-4B7C-A377-45A8E2C70AB2

It's a bit of an anachronism to get information from the dialogs. It was the WordBasic way.
In some cases like this, you still need it, since VBA doesn't offer a way to get that info.

Not sure whether you're asking some question about your code...
It looks fine, except that you'd probably reset the counter to zero for each table?

Regards,
Klaus
 
A

Ashish Dutt Sharma

Thanks for the link. I acutally am discovering dialogs for the first time in
VBA. Am at msdn now. in the code sample that i've posted, since my selection
covers both the text columns, the dialog property is returning 1 always.
Atleast that's the reason why I think it's returning 1. However if i select
just one row from the second col, it returns 2 as expected.
That's why i was wondering do i have to set the scope of the DIalog somehow
to just the current row in the iteration? And if yes how?
 
A

Ashish Dutt Sharma

And oh.. I am (un?)fortunately doing this on a Windows 95 machine running
Word 97, all this running inside a Virtual Machine. DIdn't want to cplicate
the post, but since you indicated that I might have to use an older solution,
well yes, I am doing this on an OLD platform.
 
K

Klaus Linke

The version shouldn't be an issue.

But you have to actually selected the row (myRow.Select).
The dialog will return the column number of the current selection, and since your macro didn't use the selection at all, it always returned 1 (or whatever column the cursor happened to be in).

You can turn off screen updating (Application.ScreenUpdating = False) to avoid screen flicker ... it might speed up the macro a little bit, too.

Regards,
Klaus
 
A

Ashish Dutt Sharma

DID IT!
Thanks Klaus. Your pointer did it. I figured out the selected part on my
own. And backed up a copy of the range for further processing. Here's the
final code snippet for reference of anyone who may need it:

Set oriSelect = Selection.Range.Duplicate
For Each myTable In Selection.Tables
For Each myRow In myTable.Rows
myRow.Select

If Dialogs(wdDialogFormatColumns).ColumnNo = 1 Then
Call fixLeft(myRow.Range)
Else
Call fixRight(myRow.Range)
End If

NextRow:
Next
Next
---------------------------------------------------
 

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