【发布时间】:2016-03-29 22:27:21
【问题描述】:
任务是将当前标题分配给比上一个标题低 1 级的标题。
问题在于,前一个标题会随着文档的不同而不同。
目前我有以下:
'Setting a Temp Bookmark to come back to
ActiveDocument.Bookmarks.Add Name:="CurrentPosition", Range:=Selection.Range
'Going Back to the previous Heading
Selection.GoTo What:=wdGoToBookmark, Name:="PreviousHeading"
'Determining the current and assigning the next style
If Selection.Style = ActiveDocument.Styles("Heading 1") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 2")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 2") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 3")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 3") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 4")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 4") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 5")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 5") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 6")
End If
'Going back to the new Heading
Selection.GoTo What:=wdGoToBookmark, Name:="CurrentPosition"
'Changing the Style accordingly
Selection.Style = NextHeadingStyle
作为测试,我尝试过的是:
Selection.Style = wdStyleHeading4 - 1
这会将文本设置为“标题 5”
我想要的是这样的:
'Setting a Temp Bookmark to come back to
ActiveDocument.Bookmarks.Add Name:="CurrentPosition", Range:=Selection.Range
'Going Back to the previous Heading
Selection.GoTo What:=wdGoToBookmark, Name:="PreviousHeading"
NextHeadingStyle = Selection.Style
NextHeadingStyle = NextHeadingStyle - 1
'Going back to the new Heading
Selection.GoTo What:=wdGoToBookmark, Name:="CurrentPosition"
'Changing the Style accordingly
Selection.Style = NextHeadingStyle
如果有办法做到这一点?
【问题讨论】: