<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Word通過宏統一設置樣式

      Word通過宏統一設置表格樣式、圖片樣式、標題和正文樣式、更新目錄。

      Sub A表格格式化_增強版()
          On Error Resume Next
          Application.ScreenUpdating = False
          Dim tbl As table
          Dim counter As Integer: counter = 1
          Dim response As VbMsgBoxResult
          
          For Each tbl In ActiveDocument.Tables
              Call FormatSingleTable(tbl)
              
              ' 進度提示
              If counter Mod 20 = 0 Then
                  response = MsgBox("已處理第 " & counter & " 個表格", vbOKCancel + vbInformation, "進度")
                  If response = vbCancel Then Exit For
              End If
              counter = counter + 1
          Next tbl
          
          Application.ScreenUpdating = True
          If response <> vbCancel Then
              MsgBox "完成!共處理 " & (counter - 1) & " 個表格", vbInformation
          End If
      End Sub
      
      ' 單獨處理每個表格的函數
      Sub FormatSingleTable(tbl As table)
          On Error Resume Next
          
          ' 表格基本設置
          With tbl
              .PreferredWidthType = wdPreferredWidthPercent
              .PreferredWidth = 100
              .AllowAutoFit = False
              .Rows.Alignment = wdAlignRowCenter
          End With
          
          ' 邊框設置
          With tbl.Borders
              .Enable = True
              .OutsideLineStyle = wdLineStyleSingle
              .OutsideLineWidth = wdLineWidth050pt
              .InsideLineStyle = wdLineStyleSingle
              .InsideLineWidth = wdLineWidth050pt
          End With
          
          ' 逐個單元格處理(支持合并單元格)
          Dim r As Long, c As Long
          For r = 1 To tbl.Rows.Count
              For c = 1 To tbl.Columns.Count
                  ' 只處理每個合并區域的第一個單元格
                  If Not IsMergedCell(tbl, r, c) Then
                      FormatTableCell tbl, r, c
                  End If
              Next c
          Next r
      End Sub
      
      ' 判斷是否為合并單元格的重復部分
      Function IsMergedCell(tbl As table, row As Long, col As Long) As Boolean
          On Error Resume Next
          IsMergedCell = (tbl.cell(row, col).rowIndex <> row Or tbl.cell(row, col).ColumnIndex <> col)
      End Function
      
      ' 格式化單個單元格
      Sub FormatTableCell(tbl As table, row As Long, col As Long)
          On Error Resume Next
          With tbl.cell(row, col)
              .VerticalAlignment = wdCellAlignVerticalCenter
              .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
              .Range.Font.Name = "宋體"
              .Range.Font.NameFarEast = "宋體"
              .Range.Font.Size = 10.5
              .Range.Font.Color = RGB(0, 0, 0)
              
              If row = 1 Then
                  .Range.Font.Bold = True
                  .Shading.BackgroundPatternColor = RGB(242, 242, 242)
              Else
                  .Range.Font.Bold = False
                  .Shading.BackgroundPatternColor = wdColorAutomatic
              End If
          End With
      End Sub
      
      
      '' 厘米轉磅函數(1厘米=28.35磅)
      Function CentimetersToPoints(ByVal cm As Single) As Single
          CentimetersToPoints = cm * 28.35
      End Function
      
      
      
      Sub B圖片格式化()
          ' 聲明變量
          Dim shp As Shape
          Dim ilshp As InlineShape
          Dim pageWidth As Single
          Dim leftMargin As Single
          Dim rightMargin As Single
          Dim usableWidth As Single
          
          ' 關閉屏幕更新以提高宏運行速度
          Application.ScreenUpdating = False
          
          ' 設置錯誤處理,跳過無法處理的圖片
          On Error Resume Next
          
          ' 計算頁面可用寬度(點數)
          With ActiveDocument.PageSetup
              pageWidth = .pageWidth
              leftMargin = .leftMargin
              rightMargin = .rightMargin
          End With
          
          ' 計算可用寬度 = 頁面寬度 - 左邊距 - 右邊距
          usableWidth = pageWidth - leftMargin - rightMargin
          
          ' 第一部分:處理嵌入型圖片(InlineShapes)
          For Each ilshp In ActiveDocument.InlineShapes
              If ilshp.Type = wdInlineShapePicture Or ilshp.Type = wdInlineShapeLinkedPicture Then
                  ' 設置圖片寬度為頁面可用寬度
                  ilshp.Width = usableWidth
                  ' ★ 新增:取消首行縮進并設置居中對齊
                  With ilshp.Range.ParagraphFormat
                      .CharacterUnitFirstLineIndent = 0    ' 取消字符單位首行縮進
                      .FirstLineIndent = 0                 ' 取消磅單位首行縮進
                      .Alignment = wdAlignParagraphCenter   ' 段落后中包括圖片
                  End With
              End If
          Next ilshp
          
          ' 第二部分:處理浮動型圖片(Shapes)
          For Each shp In ActiveDocument.Shapes
              If shp.Type = msoPicture Or shp.Type = msoLinkedPicture Then
                  ' 鎖定縱橫比,設置寬度為頁面可用寬度
                  shp.LockAspectRatio = msoTrue
                  shp.Width = usableWidth
                  ' ★ 新增:通過錨定段落取消首行縮進并居中對齊
                  If Not shp.Anchor Is Nothing Then
                      With shp.Anchor.ParagraphFormat
                          .CharacterUnitFirstLineIndent = 0
                          .FirstLineIndent = 0
                          .Alignment = wdAlignParagraphCenter
                      End With
                  End If
              End If
          Next shp
          
          ' 完成提示(更新提示文本)
          MsgBox "圖片設置已完成!" & vbCrLf & vbCrLf & _
                 "所有圖片已設置為頁面寬度、居中對齊,并取消首行縮進。", _
                 vbInformation, "圖片樣式設置"
          
          ' 重新開啟屏幕更新
          Application.ScreenUpdating = True
      End Sub
      
      
      
      Sub C設置正文樣式()
          ' 關閉屏幕更新和響應提示以提高宏運行速度
          Application.ScreenUpdating = False
          Application.DisplayAlerts = wdAlertsNone
          
          Dim para As Paragraph
          
          ' 遍歷文檔中的所有段落
          For Each para In ActiveDocument.Paragraphs
              ' 判斷段落樣式并應用相應格式
              Select Case para.style
                  Case "正文"
                      With para.Range.Font
                          .Name = "宋體"
                          .Size = 12    ' 小四號對應12磅
                          .Color = RGB(0, 0, 0) ' 黑色
                          .Bold = False
                          .Italic = False
                      End With
                      
                      ' ★ 新增:檢查段落是否包含圖片或表格,不進行縮進
                      If para.Range.InlineShapes.Count = 0 And para.Range.Tables.Count = 0 Then
                          With para.Range.ParagraphFormat
                              .LineSpacingRule = wdLineSpace1pt5  ' 1.5倍行距
                              .SpaceBefore = 0
                              .SpaceAfter = 0
                              .CharacterUnitFirstLineIndent = 2   ' 首行縮進2個字符
                          End With
                      Else
                          ' 對于包含圖片或表格的段落,只設置基本段落格式,不縮進
                          With para.Range.ParagraphFormat
                              .LineSpacingRule = wdLineSpace1pt5
                              .SpaceBefore = 0
                              .SpaceAfter = 0
                              .CharacterUnitFirstLineIndent = 0   ' 取消縮進
                              .FirstLineIndent = 0                ' 取消磅單位縮進
                          End With
                          
                          ' 設置表格的字體為五號
                          With para.Range.Font
                              .Name = "宋體"
                              .Size = 10.5             ' 五號對應10.5磅
                              .Color = RGB(0, 0, 0)    ' 黑色
                              .Bold = False
                              .Italic = False
                          End With
                          
                      End If
              End Select
          Next para
          
          ' 恢復屏幕更新和提示
          Application.ScreenUpdating = True
          Application.DisplayAlerts = wdAlertsAll
          
          ' 彈窗顯示設置結果
          MsgBox "正文設置已完成!" & vbCrLf & vbCrLf & _
                 "正文:  宋體,小四(12磅),1.5倍行距" & vbCrLf & _
                 "       普通段落:首行縮進2字符" & vbCrLf & _
                 "       圖片/表格段落:無縮進", _
                 vbInformation, "正文樣式設置"
      End Sub
      
      
      Sub D清除現有列表樣式()
      
          ' 清除選定區域或全文的現有列表格式
          If Selection.Range.Start = Selection.Range.End Then
              ' 如果未選中任何內容,則處理整個文檔
              ActiveDocument.Range.ListFormat.RemoveNumbers
          Else
              ' 如果已選中內容,則處理選中部分
              Selection.Range.ListFormat.RemoveNumbers
          End If
      
          ' 彈窗顯示設置結果
          MsgBox "樣式已清除!", _
                 vbInformation, "清除樣式設置"
      
      End Sub
      
      
      Sub F帶中文編號的多級列表()
      
          Dim listTemplate As listTemplate
          Set listTemplate = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
          
          With listTemplate
              ' 第1級:第一章
              With .ListLevels(1)
                  .NumberFormat = "第%1章"                   ' 設置編號格式為"第1章"等形式,%1代表第一級數字
                  .NumberStyle = wdListNumberStyleArabic     ' 設置編號樣式為阿拉伯數字
                  .LinkedStyle = "標題 1"                    ' 將此列表級別鏈接到"標題 1"樣式
                  .NumberPosition = 0                        ' 設置編號的懸掛縮進位置(單位為磅)
                  .TextPosition = 54                         ' 設置文本的縮進位置(單位為磅)
                  .StartAt = 1                               ' 設置起始編號為1
                  .TrailingCharacter = wdTrailingSpace       ' 設置編號后的尾隨字符為空格(與文本分隔)
              End With
              
              ' 第2級:1.1
              With .ListLevels(2)
                  .NumberFormat = "%1.%2"
                  .NumberStyle = wdListNumberStyleArabic
                  .LinkedStyle = "標題 2"
                  .NumberPosition = 54
                  .TextPosition = 90
                  .StartAt = 1
                  .TrailingCharacter = wdTrailingSpace
                  .ResetOnHigher = 1
              End With
              
              ' 第3級:1.1.1
              With .ListLevels(3)
                  .NumberFormat = "%1.%2.%3"
                  .NumberStyle = wdListNumberStyleArabic
                  .LinkedStyle = "標題 3"
                  .NumberPosition = 90
                  .TextPosition = 126
                  .StartAt = 1
                  .TrailingCharacter = wdTrailingSpace
                  .ResetOnHigher = 2
              End With
              
              ' 第4級:1.1.1.1
              With .ListLevels(4)
                  .NumberFormat = "%1.%2.%3.%4"
                  .NumberStyle = wdListNumberStyleArabic
                  .LinkedStyle = "標題 4"
                  .NumberPosition = 126
                  .TextPosition = 162
                  .StartAt = 1
                  .TrailingCharacter = wdTrailingSpace
                  .ResetOnHigher = 3
              End With
              
              
              ' 第5級: 1.1.1.1.1
              With .ListLevels(5)
                  .NumberFormat = "%1.%2.%3.%4.%5"
                  .NumberStyle = wdListNumberStyleArabic
                  .LinkedStyle = "標題 5"
                  .NumberPosition = 162
                  .TextPosition = 198
                  .StartAt = 1
                  .TrailingCharacter = wdTrailingSpace
                  .ResetOnHigher = 4
              End With
              
              ' 第6級:(1)
              With .ListLevels(6)
                  .NumberFormat = "(%6)"
                  .NumberStyle = wdListNumberStyleArabic
                  .LinkedStyle = "標題 6"
                  .NumberPosition = 198
                  .TextPosition = 234
                  .StartAt = 1
                  .TrailingCharacter = wdTrailingSpace
                  .ResetOnHigher = 5
              End With
              
          End With
      
          
          ' 設置標題樣式的字體格式
          SetHeadingStylesFormat
          
          
          ' 遍歷所有段落,應用標題樣式
          For Each para In ActiveDocument.Paragraphs
              If para.style Like "標題 *" Then
                  Dim level As Integer
                  level = Val(Right(para.style, 1))
                  
                  ' 保存原始對齊方式
                  originalAlignment = para.Range.ParagraphFormat.Alignment
                  
                  If level >= 1 And level <= 6 Then
                      ' 應用對應的中文標題樣式
                      para.style = ActiveDocument.Styles("標題 " & level)
                  End If
                  
                  ' 恢復原始對齊方式
                  para.Range.ParagraphFormat.Alignment = originalAlignment
                  
              End If
          Next para
          
          MsgBox "標題樣式設置完成!", vbInformation, "標題樣式設置"
          
      End Sub
      
      
      ' 設置標題樣式的字體格式
      Function SetHeadingStylesFormat()
          On Error Resume Next
          
          ' 標題1樣式設置:第一章
          With ActiveDocument.Styles("標題 1").Font
              .Name = "黑體"                   ' 字體
              .Size = 22                       ' 字號 二號
              .Bold = True                     ' 加粗
              .Color = RGB(0, 0, 0)            ' 黑色
              .Italic = False                  ' 非斜體
              .Underline = wdUnderlineNone     ' 無下劃線
          End With
          With ActiveDocument.Styles("標題 1").ParagraphFormat
              .Alignment = wdAlignParagraphLeft    ' 左對齊
              .LineSpacingRule = wdLineSpaceSingle ' 單倍行距
              .SpaceBefore = 12                ' 段前間距
              .SpaceAfter = 6                  ' 段后間距
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          ' 標題2樣式設置:1.1
          With ActiveDocument.Styles("標題 2").Font
              .Name = "黑體"
              .Size = 16                       ' 字體 三號
              .Bold = True
              .Color = RGB(0, 0, 0)            ' 黑色
              .Italic = False
          End With
          With ActiveDocument.Styles("標題 2").ParagraphFormat
              .Alignment = wdAlignParagraphLeft    ' 左對齊
              .LineSpacingRule = wdLineSpaceSingle
              .SpaceBefore = 12
              .SpaceAfter = 6
              .FirstLineIndent = 0             ' 首行不縮進
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          ' 標題3樣式設置:1.1.1
          With ActiveDocument.Styles("標題 3").Font
              .Name = "宋體"
              .Size = 14                      ' 字體 四號
              .Bold = True
              .Color = RGB(0, 0, 0)
              .Italic = False
          End With
          With ActiveDocument.Styles("標題 3").ParagraphFormat
              .Alignment = wdAlignParagraphLeft
              .LineSpacingRule = wdLineSpaceSingle
              .SpaceBefore = 6
              .SpaceAfter = 3
              .FirstLineIndent = 0
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          ' 標題4樣式設置:1.1.1.1
          With ActiveDocument.Styles("標題 4").Font
              .Name = "宋體"
              .Size = 12                  '字體 小四
              .Bold = True
              .Color = RGB(0, 0, 0)
              .Italic = False
          End With
          With ActiveDocument.Styles("標題 4").ParagraphFormat
              .Alignment = wdAlignParagraphLeft
              .LineSpacingRule = wdLineSpaceSingle
              .SpaceBefore = 6
              .SpaceAfter = 3
              .FirstLineIndent = 0
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          ' 標題5樣式設置:1.1.1.1.1
          With ActiveDocument.Styles("標題 5").Font
              .Name = "宋體"
              .Size = 12                       ' 字體 小四
              .Bold = False                    ' 不加粗
              .Color = RGB(0, 0, 0)
              .Italic = False
          End With
          With ActiveDocument.Styles("標題 5").ParagraphFormat
              .Alignment = wdAlignParagraphLeft
              .LineSpacingRule = wdLineSpaceSingle
              .SpaceBefore = 3
              .SpaceAfter = 3
              .FirstLineIndent = 0
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          ' 標題6樣式設置:(1)
          With ActiveDocument.Styles("標題 6").Font
              .Name = "宋體"
              .Size = 12
              .Bold = False
              .Color = RGB(0, 0, 0)
              .Italic = False
          End With
          With ActiveDocument.Styles("標題 6").ParagraphFormat
              .Alignment = wdAlignParagraphLeft
              .LineSpacingRule = wdLineSpaceSingle
              .SpaceBefore = 3
              .SpaceAfter = 3
              .FirstLineIndent = 0
              ' 關鍵:設置所有縮進為0
              .LeftIndent = 0
              .RightIndent = 0
              .FirstLineIndent = 0
              .CharacterUnitLeftIndent = 0
              .CharacterUnitRightIndent = 0
              .CharacterUnitFirstLineIndent = 0
          End With
          
          On Error GoTo 0
      End Function
      
      
      ' 創建目錄樣式,并刷新目錄
      Sub G刷新目錄()
          On Error Resume Next
          Application.ScreenUpdating = False
          
          Dim originalRange As Range
          Set originalRange = Selection.Range
          
          ' 檢查是否存在目錄
          If ActiveDocument.TablesOfContents.Count = 0 Then
              If MsgBox("文檔中沒有找到目錄,是否創建目錄?", vbYesNo + vbQuestion, "創建目錄") = vbYes Then
                  CreateTOC
              Else
                  Application.ScreenUpdating = True
                  Exit Sub
              End If
          End If
          
          ' 設置目錄樣式
          SetAllTOCStyles
          
          ' 刷新目錄
          UpdateAllTOC
          
          ' 返回原位置
          originalRange.Select
          
          Application.ScreenUpdating = True
          MsgBox "目錄樣式設置完成!" & vbCrLf & _
                 "字體:宋體" & vbCrLf & _
                 "字號:小四(12磅)", vbInformation, "目錄格式設置"
      End Sub
      
      ' 創建目錄(在第2頁)
      Function CreateTOC()
          ' 移動到文檔開頭
          Selection.HomeKey Unit:=wdStory
          
          ' 如果文檔頁數不足2頁,則插入分頁符直到有第2頁
          If ActiveDocument.ComputeStatistics(wdStatisticPages) < 2 Then
              Selection.InsertBreak Type:=wdPageBreak
          End If
          
          ' 移動到第1頁開頭
          MoveToPage 1
          
          ' 插入分頁符,確保目錄從新頁面開始(如果需要)
          If Selection.Information(wdActiveEndPageNumber) <> 2 Then
              Selection.InsertBreak Type:=wdPageBreak
              MoveToPage 2
          End If
          
          ' 添加"目錄"標題
          Selection.style = ActiveDocument.Styles("標題 1")
          Selection.TypeText text:="目錄"
          Selection.TypeParagraph
          
          ' 插入目錄字段
          ActiveDocument.TablesOfContents.Add _
              Range:=Selection.Range, _
              RightAlignPageNumbers:=True, _
              UseHeadingStyles:=True, _
              UpperHeadingLevel:=1, _
              LowerHeadingLevel:=3, _
              IncludePageNumbers:=True, _
              UseHyperlinks:=True, _
              AddedStyles:="", _
              UseFields:=True, _
              TableID:=""
          
          ' 在目錄后添加分頁符,確保后續內容從新頁面開始
          Selection.InsertBreak Type:=wdPageBreak
          
      End Function
      
      ' 跳轉到指定頁碼
      Function MoveToPage(pageNumber As Integer)
          On Error Resume Next
          Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pageNumber
      End Function
      
      ' 設置所有目錄樣式
      Function SetAllTOCStyles()
          Dim i As Integer
          Dim style As style
          
          ' 設置1-9級目錄樣式
          For i = 1 To 9
              SetTOCStyleWithLevel "目錄 " & i, "宋體", 12
              SetTOCStyleWithLevel "TOC " & i, "宋體", 12
          Next i
      End Function
      
      ' 設置帶級別的目錄樣式
      Function SetTOCStyleWithLevel(styleName As String, fontName As String, fontSize As Single)
          On Error Resume Next
          Dim style As style
          
          Set style = ActiveDocument.Styles(styleName)
          If Not style Is Nothing Then
              With style.Font
                  .Name = fontName
                  .NameFarEast = fontName
                  .Size = fontSize
              End With
              
              ' 設置縮進(根據級別)
              With style.ParagraphFormat
                  .LeftIndent = CentimetersToPoints(0)
                  .FirstLineIndent = CentimetersToPoints(0)
                  .LineSpacingRule = wdLineSpaceSingle
                  .SpaceAfter = 3
              End With
          End If
      End Function
      
      ' 刷新所有目錄
      Function UpdateAllTOC()
          Dim toc As TableOfContents
          Dim table As TableOfFigures
          
          ' 刷新正文目錄
          For Each toc In ActiveDocument.TablesOfContents
              toc.Update
          Next toc
          
          ' 刷新圖表目錄
          For Each table In ActiveDocument.TablesOfFigures
              table.Update
          Next table
      End Function
      
      
      
      Sub H調整文檔中標題等級()
          Dim para As Paragraph
          Dim currentStyle As style
          Dim highestLevel As Integer
          Dim levelOffset As Integer
          Dim i As Integer
          
          ' 初始化最高級別為最大值
          highestLevel = 9
          
          ' 第一步:掃描文檔,找出最低的標題級別(數字最小的)
          For Each para In ActiveDocument.Paragraphs
              If para.style Like "標題 *" Then
                  ' 提取標題級別數字
                  i = Val(Right(para.style, 1))
                  If i < highestLevel Then
                      highestLevel = i
                  End If
              End If
          Next para
          
          ' 如果沒有找到任何標題,退出宏
          If highestLevel = 9 Then
              MsgBox "文檔中沒有找到標題樣式。"
              Exit Sub
          End If
          
          ' 第二步:如果最高級別已經是1,無需調整
          If highestLevel = 1 Then
              MsgBox "文檔中已包含級別1標題,無需調整。"
              Exit Sub
          End If
          
          ' 計算需要升級的級數
          levelOffset = highestLevel - 1
          
          ' 第三步:遍歷所有段落,調整標題級別
          For Each para In ActiveDocument.Paragraphs
              If para.style Like "標題 *" Then
                  ' 保存原始對齊方式
                  originalAlignment = para.Range.ParagraphFormat.Alignment
                  
                  ' 提取當前標題級別
                  i = Val(Right(para.style, 1))
                  
                  ' 計算新的標題級別
                  Dim newLevel As Integer
                  newLevel = i - levelOffset
                  
                  ' 確保新級別在有效范圍內(1-9)
                  If newLevel >= 1 And newLevel <= 9 Then
                      ' 應用新的標題樣式
                      para.style = "標題 " & newLevel
                  ElseIf newLevel < 1 Then
                      ' 如果計算出的級別小于1,強制設為1
                      para.style = "標題 1"
                  End If
                  
                  ' 恢復原始對齊方式
                  para.Range.ParagraphFormat.Alignment = originalAlignment
                  
              End If
          Next para
          
          MsgBox "標題級別調整完成!原最高級別" & highestLevel & "已調整為級別1。"
      End Sub
      
      
      
      Sub D清除現有列表樣式_非標準編號()
          Dim para As Paragraph
          Dim rng As Range
          Dim counter As Integer
          Dim originalText As String
          Dim newText As String
          
          counter = 0
          Application.ScreenUpdating = False
          
          For Each para In ActiveDocument.Paragraphs
              If para.style Like "標題 *" Then
                  Set rng = para.Range
                  originalText = rng.text
                  
                  ' 去除段落結束標記(通常是回車符)
                  originalText = Left(originalText, Len(originalText) - 1)
                  
                  ' 檢查是否有編號模式
                  If HasNumberPattern(originalText) Then
                      newText = RemoveNumberPatterns(originalText)
                      
                      ' 只有當文本確實發生變化時才更新
                      If newText <> originalText Then
                          ' 重要:只替換文本內容,保持段落結構完整
                          rng.MoveEnd wdCharacter, -1 ' 排除段落標記
                          rng.text = newText
                          counter = counter + 1
                          
                          ' 重新應用標題樣式
                          Dim level As Integer
                          level = GetHeadingLevel(para.style)
                          If level > 0 Then
                              rng.style = "標題 " & level
                          End If
                      End If
                  End If
                  
                  ' 清除列表格式(安全操作)
                  On Error Resume Next
                  para.Range.ListFormat.RemoveNumbers
                  On Error GoTo 0
              End If
          Next para
          
          Application.ScreenUpdating = True
          MsgBox "已快速清理 " & counter & " 個標題的非標準編號。"
      End Sub
      
      
      Function RemoveNumberPatterns(text As String) As String
          Dim result As String
          result = text
          
          ' 去除各種常見的編號模式
          ' 1. 數字+點+空格 (如 "1. ", "1.1. ", "1.1.1. ")
          ' 2. 數字+空格 (如 "1 ", "1.1 ","1.1.1 ")
          result = RegExReplace(result, "^\d+\.\d+\.\d+\.\d+\.\d+\.\s?", "")
          result = RegExReplace(result, "^\d+\.\d+\.\d+\.\d+\.\d+\s?", "")
          
          result = RegExReplace(result, "^\d+\.\d+\.\d+\.\d+\.\s?", "")
          result = RegExReplace(result, "^\d+\.\d+\.\d+\.\d+\s?", "")
          
          result = RegExReplace(result, "^\d+\.\d+\.\d+\.\s?", "")
          result = RegExReplace(result, "^\d+\.\d+\.\d+\s?", "")
          
          result = RegExReplace(result, "^\d+\.\d+\.\s?", "")
          result = RegExReplace(result, "^\d+\.\d+\s?", "")
          
          result = RegExReplace(result, "^\d+\.\s?", "")
          result = RegExReplace(result, "^\d+\s?", "")
          
          ' 3. 中文數字+頓號 (如 "一、", "二、")
          result = RegExReplace(result, "^[一二三四五六七八九十]、", "")
          
          ' 4. 字母+點+空格 (如 "A. ", "a. ")
          result = RegExReplace(result, "^[A-Za-z]\.\s?", "")
          
          ' 5. 羅馬數字+點+空格 (如 "I. ", "II. ")
          result = RegExReplace(result, "^[IVXLCDM]+\.\s?", "")
          
          ' 6. 帶括號的數字 (如 "(1)", "(1.1)")
          result = RegExReplace(result, "^\(\d+\)\s?", "")
          result = RegExReplace(result, "^\(\d+\.\d+\)\s?", "")
          
          ' 7. 去除開頭空格
          result = Trim(result)
          
          RemoveNumberPatterns = result
      End Function
      
      
      ' 正則表達式替換函數
      Function RegExReplace(text As String, pattern As String, replacement As String) As String
          Dim regEx As Object
          Set regEx = CreateObject("VBScript.RegExp")
          
          With regEx
              .Global = True
              .IgnoreCase = True
              .MultiLine = False
              .pattern = pattern
          End With
          
          If regEx.Test(text) Then
              RegExReplace = regEx.Replace(text, replacement)
          Else
              RegExReplace = text
          End If
      End Function
      
      
      Function HasNumberPattern(text As String) As Boolean
          ' 檢測文本是否包含常見的編號模式
          Dim patterns(10) As String
          Dim i As Integer
          
          patterns(0) = "^\d+\."              ' 數字+點
          patterns(1) = "^\d+"                ' 數字
          patterns(2) = "^[一二三四五六七八九十]、" ' 中文數字
          patterns(3) = "^[A-Za-z]\."         ' 字母+點
          patterns(4) = "^[IVXLCDM]+\."       ' 羅馬數字
          patterns(5) = "^\(\d+\)"            ' 括號數字
          
          For i = 0 To 5
              If RegExTest(text, patterns(i)) Then
                  HasNumberPattern = True
                  Exit Function
              End If
          Next i
          
          HasNumberPattern = False
      End Function
      
      Function RegExTest(text As String, pattern As String) As Boolean
          Dim regEx As Object
          Set regEx = CreateObject("VBScript.RegExp")
          
          With regEx
              .Global = False
              .IgnoreCase = True
              .pattern = pattern
          End With
          
          RegExTest = regEx.Test(text)
      End Function
      
      Function GetHeadingLevel(styleName As String) As Integer
          If styleName Like "標題 *" Then
              GetHeadingLevel = Val(Right(styleName, 1))
          Else
              GetHeadingLevel = 0
          End If
      End Function
      

        

      posted @ 2025-10-09 16:05  業余磚家  閱讀(17)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产精品熟妇视频国产偷人| 不卡av电影在线| 熟女一区二区中文在线| 久久超碰97人人做人人爱| 国内揄拍国内精品人妻久久| 免费国产va在线观看| 国产一区二区三区色成人| 黄色网站免费在线观看| 亚洲av成人一区在线| 国产成人av三级在线观看| 2021av在线天堂网| 一道本AV免费不卡播放| 国产亚洲一区二区三区成人| 亚洲中文久久久精品无码| 国产精品露脸视频观看| 99精品国产一区在线看| 五月丁香六月综合缴清无码| 亚洲成在人线AV品善网好看| 久热re这里精品视频在线6| 国产极品美女网站在线观看| 久久午夜私人影院| 人妻少妇不满足中文字幕| 日产日韩亚洲欧美综合下载| 精品久久免费国产乱色也| 久久久久人妻一区精品色| 国精偷拍一区二区三区| 国产成人高清在线观看视频| 国产普通话对白刺激| 欧洲无码一区二区三区在线观看| 国产精品青青在线观看爽香蕉| 人妻伦理在线一二三区| 成人3D动漫一区二区三区| av鲁丝一区鲁丝二区鲁丝三区| 亚洲国产欧美一区二区好看电影| 国产乱xxxxx97国语对白| 中文字幕人妻中出制服诱惑| 精品国产午夜肉伦伦影院| 国产中文字幕精品在线| 国产视频最新| 制服jk白丝h无内视频网站| 亚洲第一国产综合|