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 2005

Tip: Looking for answers? Try searching our database.

Checking number of text columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sol Apache - 03 Oct 2005 12:01 GMT
Hello
I have been trying to set a toggle macro so that if a particular section has
one text column then it changes to two columns; and if the section has two
text columns then it changes to one.

I am having trouble setting the If, else statement and every variation I
have tried VB rejects it. For example

If ActiveDocument.Sections(2).PageSetup.TextColumns.numColumns = 1 then

Can anyone help me with the syntax to get this working please. It could be
that the rest of the macro won¹t work either, but I¹d like to get beyond
this line for a start.

TIA
Stefan Blom - 03 Oct 2005 13:29 GMT
Try the following (basic) macro:

Sub Test()
  Dim t As TextColumns
  Dim numcols As Long

  If ActiveDocument.Sections.Count<2 Then Exit Sub

  Set t = ActiveDocument.Sections(2).PageSetup.TextColumns

  numcols = t.Count

  Select Case numcols
     Case 1
     t.SetCount 2
     Case 2
     t.SetCount 1
     Case Else
     'What should happen if there
     'are more than 2 columns?
  End Select
End Sub

Signature

Stefan Blom
Microsoft Word MVP

> Hello
> I have been trying to set a toggle macro so that if a particular section has
[quoted text clipped - 11 lines]
>
> TIA
Sol Apache - 03 Oct 2005 13:52 GMT
Thank you for this. There should be only two or one columns, so do I just
leave out the else bit?

Thanks

Sol

On 3/10/05 13:29, in article uAX3KYByFHA.448@TK2MSFTNGP11.phx.gbl, "Stefan
Blom" <no.spam@please.xyz> wrote:

> Try the following (basic) macro:
>
[quoted text clipped - 18 lines]
>    End Select
> End Sub
Stefan Blom - 03 Oct 2005 14:08 GMT
Are you sure that you would never run the macro in a document that has
more than two columns? Then you could perhaps skip the "Else" part.
However, I would recommend that you (under Case Else) repeat either of
the calls to the SetCount method. For example:

  t.SetCount 1

That way, the macro is logically complete, in the sense that it covers
all possible cases.

Signature

Stefan Blom
Microsoft Word MVP

> Thank you for this. There should be only two or one columns, so do I just
> leave out the else bit?
[quoted text clipped - 28 lines]
> >    End Select
> > End Sub
Sol Apache - 03 Oct 2005 15:50 GMT
You are probably right Stefan - I should cover all instances. The macro is
in a button in a template where the user can make the Table of Contents
section either one column or two column. It¹s unlikely the users would know
how to create columns, but I can always be proved wrong.

Thanks very much for your help. Your macro works beautifully.

Sol

On 3/10/05 14:08, in article Oc3$cuByFHA.2848@TK2MSFTNGP15.phx.gbl, "Stefan
Blom" <no.spam@please.xyz> wrote:

> Are you sure that you would never run the macro in a document that has
> more than two columns? Then you could perhaps skip the "Else" part.
[quoted text clipped - 5 lines]
> That way, the macro is logically complete, in the sense that it covers
> all possible cases.
Stefan Blom - 04 Oct 2005 09:03 GMT
I'm glad I could help.

Signature

Stefan Blom
Microsoft Word MVP

> You are probably right Stefan - I should cover all instances. The macro is
> in a button in a template where the user can make the Table of Contents
[quoted text clipped - 17 lines]
> > That way, the macro is logically complete, in the sense that it covers
> > all possible cases.
 
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.