Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

How to determine current text column number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon McInnes - 25 Oct 2006 15:41 GMT
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
Jean-Guy Marcil - 25 Oct 2006 18:47 GMT
Simon McInnes was telling us:
Simon McInnes nous racontait que :

> Hi,
>
[quoted text clipped - 14 lines]
> 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...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Simon McInnes - 26 Oct 2006 09:19 GMT
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

> Simon McInnes was telling us:
> Simon McInnes nous racontait que :
[quoted text clipped - 24 lines]
> Your best bet is probably to get the paragraph starting position in relation
> to the left margin...
Jean-Guy Marcil - 26 Oct 2006 13:40 GMT
Simon McInnes was telling us:
Simon McInnes nous racontait que :

> Thanks for your reply. I have found a way but its not great.
>
[quoted text clipped - 5 lines]
> 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...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.