用VBA为word创建文档结构图

[ 2009-04-14 17:22:58 | Author: wujimmy ]
Font Size: Large | Medium | Small
Sub 以段为单位建目录_wjm090414()
On Error Resume Next

maxlen = 15 '设定段落最大字数
minlen = 2 '设定段落最小字数
Dim myParagraph As Paragraph
'对每一段落进行操作
For Each myParagraph In ActiveDocument.Paragraphs

'
If myParagraph.Range.Font.Size > 1000 Then Exit For
'
len1 = Len(myParagraph.Range.Text)
If len1 <= maxlen And len1 >= minlen Then
myParagraph.Range.Font.Size = 13.5
'myParagraph.Range.Font.Size = myParagraph.Range.Font.Size + 2
myParagraph.Range.Bold = True

myParagraph.OutlineLevel = wdOutlineLevel1
Else
myParagraph.Range.Bold = False
'myParagraph.Range.Font.Size = myParagraph.Range.Font.Size + 2
myParagraph.OutlineLevel = wdOutlineLevelBodyText
myParagraph.Range.Font.Size = 10.5

End If

Next myParagraph
End Sub

'版本二,用是过滤含"第" "章"字
Sub 创建文档结图_wjm090414()
On Error Resume Next

maxlen = 55 '设定段落最大字数
minlen = 2 '设定段落最小字数
Dim myParagraph As Paragraph
'对每一段落进行操作
For Each myParagraph In ActiveDocument.Paragraphs

'
If myParagraph.Range.Font.Size > 1000 Then Exit For
'
str1 = myParagraph.Range.Text
len1 = Len(str1)

'b1 = InStr(str1, ":") = 0
'b2 = InStr(str1, ":") = 0
'b3 = InStr(str1, ",") = 0
'b4 = InStr(str1, ",") = 0
'If len1 <= maxlen And len1 >= minlen And b1 And b2 And b3 And b4 Then

b1 = (InStr(str1, ":") <> 0) Or (InStr(str1, ":") <> 0) Or ((InStr(str1, "第") <> 0) And (InStr(str1, "章") <> 0))

If len1 <= maxlen And len1 >= minlen And b1 Then
myParagraph.Range.Font.Size = 13.5
'myParagraph.Range.Font.Size = myParagraph.Range.Font.Size + 2
myParagraph.Range.Bold = True

myParagraph.OutlineLevel = wdOutlineLevel1
Else
myParagraph.Range.Bold = False
'myParagraph.Range.Font.Size = myParagraph.Range.Font.Size + 2
myParagraph.OutlineLevel = wdOutlineLevelBodyText
myParagraph.Range.Font.Size = 10.5

End If

Next myParagraph
End Sub
[Last Modified By wujimmy, at 2009-04-17 09:53:49]
Comments Feed Comments Feed: http://www.jgcad.com/feed.asp?q=comment&id=332

There is no comment on this article.

Post Comment
Smilies
[微笑] [忧伤] [鬼脸] [高兴] [眨眼] [困惑] [爱意] [脸红] [吐舌头] [吻你]
[惊诧] [生气] [坏笑] [耍酷] [担心] [魔鬼] [大哭] [大笑] [不高兴] [挤眉弄眼]
[天使] [你讨厌] [不要] [瞌睡] [想主意] [不舒服] [请安静] [别理我] [小丑] [呆瓜]
[我好累] [好诱人] [考虑考虑] [哦!] [鼓掌] [小猪] [老牛] [猴子] [小鸡] [玫瑰花]
[好运气] [南瓜头] [咖啡] [好点子] [骷髅头] [外星人1] [外星人2] [郁闷] [牛仔] [祈祷]
[着魔了] [发财啦] [吹口哨] [你说谎] [被扁了] [马道成功] [别这样] [跳舞] [拥抱你]
Enable UBB Codes
Auto Convert URL
Show Smilies
自动复制
Hidden Comment
Username:   Password:   Register Now?