Checking number of text columns

S

Sol Apache

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
 
S

Stefan Blom

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

--
Stefan Blom
Microsoft Word MVP


in message news:BF66CE21.7FA6%[email protected]...
 
S

Sol Apache

Thank you for this. There should be only two or one columns, so do I just
leave out the else bit?

Thanks

Sol
 
S

Stefan Blom

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.
 
S

Sol Apache

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
 

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