Log in

View Full Version : Solved: TextColumn count?



gotmatt
08-05-2011, 02:44 PM
Hi all!

I've searched all through the interwebs and have had no luck with this issue, so thanks ahead of time!

I have a few documents in which I need to format a very specific paragraph. The paragraph is at the beginning of a section, but the number of that section is not always the same. The fact that its section always has 3 columns is the same in all my documents.

I need to figure out a way to test what the number of text columns is. If the number is three, then I know to edit its first paragraph. I'm having trouble testing this.

I've tried using the textcolumn object like:
Activedocument.sections(x).pagesetup.textcolumns.count
in the context of:
For m = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(m)
msgbox ActiveDocument.Sections(m).PageSetup.TextColumns.Count
End With
Next
Word will have none of it :(

Have any ideas? Thanks!

-Gotmatt

Frosty
08-05-2011, 03:55 PM
Well, your code is a bit unnecessary in that you use a with statement and then don't use it...

But why can't you do this?

Sub Find3ColumnSection()
Dim i As Integer
For i = 1 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).PageSetup.TextColumns.Count = 3 Then
MsgBox "3 column setup found in Section: " & CStr(i)
End If
Next
End Sub

Frosty
08-05-2011, 03:57 PM
Just as a suggestion... sometimes people use 3 column tables to get a different kind of column. But .TextColumns.Count works fine on my Word 2010.

If you haven't declared your variable or you don't use Option Explicit... it's possible that vba is getting confused, but otherwise... you need to post a document.

gotmatt
08-12-2011, 07:37 AM
Thanks guys!

I changed to Option Explicit and used that exact syntax, but it still did not work. What I discovered was that a frame in my first section was causing issues. By starting my range at section 2 through the end of the document, everything worked well!

Now that I'm at ten posts, I'll be able to post documents too! :)

gotmatt
08-12-2011, 07:40 AM
For b = 2 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(b).PageSetup.TextColumns.Count = 3 Then
With ActiveDocument.Sections(b).Range
.Paragraphs(1).Range.Select
End With
End If
Next


...was the resulting code, if anyone was interested. This allowed me to determine the index section of the document (the only section with 3 columns) and then select it's first paragraph. This is probably quite simple in the big scheme of things, but it sure threw me for a loop haha.