How to determine current text column number

S

Simon McInnes

Hi,

I need to work out (using the api) which text column the cursor is currently
in.
I have tried Selection.Range.Information(wdStartOfRangeColumnNumber) but
this always gives the value -1 (it only seems to work correctly for table
columns and not text columns). How can I do this? I am using Word
v11.8026.8028.

thanks.

Simon

Steps
Create a blank document.
Change section to two column
Insert a column break and move the insertion point to the second column
Find out the current column number using the api
 
J

Jean-Guy Marcil

Simon McInnes was telling us:
Simon McInnes nous racontait que :
Hi,

I need to work out (using the api) which text column the cursor is
currently in.
I have tried Selection.Range.Information(wdStartOfRangeColumnNumber)
but this always gives the value -1 (it only seems to work correctly
for table columns and not text columns). How can I do this? I am
using Word v11.8026.8028.

thanks.

Simon

Steps
Create a blank document.
Change section to two column
Insert a column break and move the insertion point to the second
column Find out the current column number using the api

Word does not work like that.
You may be in a two column mode, but Word sees it as a continuous story
(when you get to the end of the column, go the top of the next one..

Your best bet is probably to get the paragraph starting position in relation
to the left margin...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Simon McInnes

Thanks for your reply. I have found a way but its not great.

You can use the Word Dialogs -
Application.Dialogs(wdDialogFormatColumns).ColumnNo property. This is a real
pain in C# but its do-able. Using dialogs has its drawbacks like not working
on protected parts of the document but its better than nothing. Its a shame
its not available through the Range.Information property but hey thats just
another Word annoyance we have to live with!

Simon
 
J

Jean-Guy Marcil

Simon McInnes was telling us:
Simon McInnes nous racontait que :
Thanks for your reply. I have found a way but its not great.

You can use the Word Dialogs -
Application.Dialogs(wdDialogFormatColumns).ColumnNo property. This is
a real pain in C# but its do-able. Using dialogs has its drawbacks
like not working on protected parts of the document but its better
than nothing. Its a shame its not available through the
Range.Information property but hey thats just another Word annoyance
we have to live with!

Good one.

If you find that working with dialogs is too much of a pain, try something
like:

If Format(PointsToInches(Selection.Range.Paragraphs(1) _
.Range.Information(wdHorizontalPositionRelativeToPage)), "#.#0") _
Format(PointsToInches(Selection.Sections(1).PageSetup _
.LeftMargin), "#.#0") Then

MsgBox "You are in the second column."
Else
MsgBox "You are in the first column."
End If

Of course, you will have to adapt if you have more than 2 columns...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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