Microsoft Developer Network >
Página principal de foros
>
Visual Basic for Applications (VBA)
>
Collapse Word paragraph using macro
Collapse Word paragraph using macro
- I'm trying to write a macro that will expand/collapse a paragraph in Word 2007. I have posted part of the code below, which works fine until the paragraph is more than 50 lines. When the paragraph is more than 50 lines, the Boolean value changes to 99999 and the macro doesn't work anymore. Am I hitting a known limitation that I just don't know about?
If bkmk.Name = "Grow" Then
If bkmk.Range.Font.Hidden = True Then
bkmk.Range.Font.Hidden = False
Else
bkmk.Range.Font.Hidden = True
End If
End If
Todas las respuestas
Mostly this '99999' occurs when there are mixed results - if some lines in the range are hidden and some are not. But this is a strange behavior, might be a bug in Office.
If that is the case then you need to have some workaround like this
Sub asasa() Dim bkmk As Bookmark Dim line1 As Line If bkmk.Name = "Grow" Then If bkmk.Range.Font.Hidden = True Then bkmk.Range.Font.Hidden = False ElseIf bkmk.Range.Font.Hidden = True Then bkmk.Range.Font.Hidden = True Else For Each p1 In bkmk.Range.Paragraphs If p1.Range.Font.Hidden = True Then p1.Range.Font.Hidden = False End If Next p1 End If End If End Sub
Cheers
Shasur
http://www.vbadud.blogspot.com- Shasur, I tried using the example you provided.....is p1 meant to be line1 as you defined earlier?
Thanks,
Heather Hi Heather
P1 refers to paragraph (each paragraph in the bookmark range)
Cheers
Shasur
http://www.vbadud.blogspot.com- Ok, I have modified my code to this:
Dim bkmk As Bookmark
Dim line1 As Line
Dim p1 As Paragraph
For Each bkmk In ActiveDocument.Bookmarks
If bkmk.Name = "Grow" Then
If bkmk.Range.Font.Hidden = True Then
For Each p1 In bkmk.Range.Paragraphs
p1.Range.Font.Hidden = False
Next p1
Else
For Each p1 In bkmk.Range.Paragraphs
p1.Range.Font.Hidden = True
Next p1
End If
End If
Next bkmk
But it still doesn't work over 50 lines. Has anyone been able to change the font to hidden for more than 50 lines?
Thanks
Heather

