国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

word vba自動(dòng)化排版-設(shè)置標(biāo)題模板樣式、標(biāo)題、正文、圖表、頁(yè)面、上下標(biāo)等設(shè)置、刪除空白行、刪除分頁(yè)符分節(jié)符、刪除空格等

這篇具有很好參考價(jià)值的文章主要介紹了word vba自動(dòng)化排版-設(shè)置標(biāo)題模板樣式、標(biāo)題、正文、圖表、頁(yè)面、上下標(biāo)等設(shè)置、刪除空白行、刪除分頁(yè)符分節(jié)符、刪除空格等。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

word vba自動(dòng)化排版-設(shè)置標(biāo)題模板樣式、標(biāo)題、正文、圖表、頁(yè)面、上下標(biāo)等設(shè)置、刪除空白行、刪除分頁(yè)符分節(jié)符、刪除空格等

目錄

1.前提

2.思路

3.word中設(shè)置

4.效果圖

5.經(jīng)驗(yàn)教訓(xùn)

6.直接上代碼


1.前提

? ? ? ? 需求:工作中涉及自動(dòng)識(shí)別大量的文字報(bào)告(ocr完成),然后對(duì)報(bào)告進(jìn)行排版,手動(dòng)排版效率超級(jí)慢,因此探索了一下word vba自動(dòng)排版

? ? ? ? 參考:chatgpt、word vba官網(wǎng)文檔、這篇博客csdn、這篇博客知乎、還有上下標(biāo)的博客不知出處

? ? ? ? 注意:不要期望別人都給代碼注釋好這個(gè)參數(shù)、這個(gè)函數(shù)是什么作用什么意思,像CentimetersToPoints、CharacterUnitFirstLineIndent等等,去官網(wǎng)文檔查看一下才最有深刻印象。

著重理解官網(wǎng)文檔selection、activedocument的關(guān)聯(lián),以及word 對(duì)象之間的關(guān)聯(lián)(主要看對(duì)象屬性里面有哪些 跳轉(zhuǎn)一下查看),像inlinshape.range.ParagraphFormat嵌入式圖片的段落樣式設(shè)置等等。。。

2.思路

? ? ? ?先了解一下基礎(chǔ)語(yǔ)法!

????????①對(duì)于標(biāo)題模板樣式、段落文字的樣式設(shè)置 主要用錄制宏來(lái)實(shí)現(xiàn),基于此修改代碼

? ? ? ? ②對(duì)于find、段落、document、selection等的函數(shù)參數(shù)要去官網(wǎng)查看文檔

? ? ? ? ③對(duì)于刪除分頁(yè)符等參考的chatgpt,國(guó)內(nèi)的大模型不行

? ? ? ? ④對(duì)于上下標(biāo),參考的不知出處的博客-感謝

? ? ? ? ⑤設(shè)置圖表樣式 參考官網(wǎng)、博客、chatgpt

? ? ? ? 錄制宏不是萬(wàn)能的,對(duì)于刪除分頁(yè)符、設(shè)置圖表樣式這樣的操作,錄制宏的代碼單獨(dú)執(zhí)行不起作用!

? ? ? ? 若想精通熟練使用vba進(jìn)行排版,還是需要去官網(wǎng)了解vba的對(duì)象結(jié)構(gòu),以及函數(shù)用法。

? ? ? ? 直接上手用,若復(fù)雜操作會(huì)比較依賴chatgpt,實(shí)際上很多參數(shù)不知道啥作用,查看官方文檔需要較長(zhǎng)時(shí)間理解。

? ? ? ? 代碼可以在wps中運(yùn)行,但是樣式有的不盡人意。

3.word中設(shè)置

? ? ? ? ①先設(shè)置 開(kāi)發(fā)工具:文件->選項(xiàng)->信任中心設(shè)置->啟用宏

? ? ? ? ②打開(kāi) 開(kāi)發(fā)工具->vb編輯器->工具->引用->勾選“Microsoft VBScript Regular Expressions 5.5”

4.效果圖

? ? ? ? TODO

5.經(jīng)驗(yàn)教訓(xùn)

? ? ? ? ①對(duì)于段落(非圖表)參數(shù)越多越好,參數(shù)之間會(huì)互相影響(使用錄制宏)

? ? ? ? ②對(duì)于圖表,參數(shù)不一定越多越好,有的參數(shù)互相影響,導(dǎo)致效果有問(wèn)題

6.直接上代碼

? ? ? ? 涉及:設(shè)置標(biāo)題圖片模板樣式、標(biāo)題、正文、圖表、頁(yè)面、上下標(biāo)等樣式、刪除空白行、刪除分頁(yè)符分節(jié)符、刪除空格等文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-800972.html

Sub 設(shè)置標(biāo)題正文模板樣式1()
'
' 設(shè)置標(biāo)題正文模板樣式 宏
' 設(shè)置2級(jí)標(biāo)題、正文的字體段落、圖片樣式模板
'
    With ActiveDocument.Styles(wdStyleHeading2).Font
        .NameFarEast = "宋體"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 22
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Scaling = 100
        .Kerning = 1
        .Animation = wdAnimationNone
        .DisableCharacterSpaceGrid = False
        .EmphasisMark = wdEmphasisMarkNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    With ActiveDocument.Styles(wdStyleHeading2).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = True
        .PageBreakBefore = True
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevel2
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    ActiveDocument.Styles(wdStyleHeading2).NoSpaceBetweenParagraphsOfSameStyle = False
    With ActiveDocument.Styles(wdStyleHeading2)
        .AutomaticallyUpdate = False
        .BaseStyle = wdStyleNormal
        .NextParagraphStyle = wdStyleNormal
    End With

    '新建 圖片樣式 判斷是否存在
    On Error Resume Next  ' 暫時(shí)禁用錯(cuò)誤處理
    styleExists = Not (ActiveDocument.Styles("圖片樣式") Is Nothing)
    On Error GoTo 0       ' 恢復(fù)正常的錯(cuò)誤處理

    If Not styleExists Then
        ActiveDocument.Styles.Add Name:="圖片樣式", Type:=wdStyleTypeParagraph
    End If
    
    ActiveDocument.Styles("圖片樣式").AutomaticallyUpdate = True
    With ActiveDocument.Styles("圖片樣式").Font
        .NameFarEast = "宋體"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 10.5
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Scaling = 100
        .Kerning = 1
        .Animation = wdAnimationNone
        .DisableCharacterSpaceGrid = False
        .EmphasisMark = wdEmphasisMarkNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    With ActiveDocument.Styles("圖片樣式").ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
        .WidowControl = False
        .KeepWithNext = True
        .KeepTogether = True
        .PageBreakBefore = True
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .OutlineLevel = wdOutlineLevelBodyText
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    ActiveDocument.Styles("圖片樣式").NoSpaceBetweenParagraphsOfSameStyle = False
    ActiveDocument.Styles("圖片樣式").ParagraphFormat.TabStops.ClearAll
    With ActiveDocument.Styles("圖片樣式").ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = wdColorAutomatic
        End With
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        With .Borders
            .DistanceFromTop = 1
            .DistanceFromLeft = 4
            .DistanceFromBottom = 1
            .DistanceFromRight = 4
            .Shadow = False
        End With
    End With
    ActiveDocument.Styles("圖片樣式").Frame.Delete
    
    MsgBox "標(biāo)題正文模板樣式設(shè)置完成"
End Sub


Sub 設(shè)置頁(yè)面參數(shù)2()
'
'設(shè)置初始化:取消所有樣式、設(shè)置頁(yè)邊距、設(shè)置紙張大小、頁(yè)眉頁(yè)腳邊距、每頁(yè)行數(shù)、每行字?jǐn)?shù)、設(shè)置所有段落為正文樣式
'
    Selection.WholeStory
    Selection.ClearFormatting
    Selection.Range.HighlightColorIndex = wdNoHighlight
    
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(2.54)
        .BottomMargin = CentimetersToPoints(2.54)
        .LeftMargin = CentimetersToPoints(3.17)
        .RightMargin = CentimetersToPoints(3.17)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.5)
        .FooterDistance = CentimetersToPoints(1.75)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
        .CharsLine = 39
        .LinesPage = 44
        .LayoutMode = wdLayoutModeGrid
    End With
    ' 設(shè)置正文樣式
    Selection.Style = ActiveDocument.Styles(wdStyleNormal)
    
    Selection.HomeKey Unit:=wdStory
    MsgBox "頁(yè)面參數(shù)樣式設(shè)置完成"

End Sub


Sub 刪除空白行3()
'
'先執(zhí)行刪除空白行(不可等設(shè)置完樣式后再執(zhí)行),再將全文所有空格刪除
'
    Dim para As Paragraph
    Dim isBlank As Boolean
    
    For Each para In ActiveDocument.Paragraphs
        isBlank = True
        If Len(para.Range.text) <> 1 Then
            isBlank = False
        End If
        
        If para.Range.Information(wdWithInTable) = False Then
            If isBlank Then
                para.Range.Delete
            End If
        End If
    Next
    ActiveDocument.Content.Find.Execute FindText:=" ", ReplaceWith:="", Replace:=wdReplaceAll
    MsgBox "已刪除所有空白行(非表格內(nèi))、空格"
End Sub

Sub 刪除分頁(yè)符4_1()
'chatgpt生成 需要去了解While .Execute用法、Collapse 等
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Selection.HomeKey Unit:=wdStory
    Dim rng As Range
    Set rng = ActiveDocument.Content

    Dim regEx As Object
    Set regEx = CreateObject("VBScript.RegExp")
    With regEx
        .Global = True
        .pattern = "\d+"
    End With
    With rng.Find
        .ClearFormatting
        .text = "^m"
        .Forward = True
        .Wrap = wdFindStop

        While .Execute
            Dim lineText As String
            lineText = rng.Paragraphs(1).Range.text

            If regEx.test(lineText) Then
                Dim matches As Object
                Set matches = regEx.Execute(lineText)
                If matches.Count > 0 Then
                    rng.Paragraphs(1).Range.Delete
                End If
            End If

            rng.Collapse Direction:=wdCollapseEnd
            rng.MoveStart Unit:=wdCharacter, Count:=1
        Wend
    End With
    
End Sub

Sub 刪除分節(jié)符4_2()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Selection.HomeKey Unit:=wdStory
    Dim rng As Range
    Set rng = ActiveDocument.Content

    Dim regEx As Object
    Set regEx = CreateObject("VBScript.RegExp")
    With regEx
        .Global = True
        .pattern = "\d+"
    End With

    With rng.Find
        .ClearFormatting
        .text = "^b"
        .Forward = True
        .Wrap = wdFindStop

        While .Execute

            Dim lineText As String
            lineText = rng.Paragraphs(1).Range.text

            If regEx.test(lineText) Then
                Dim matches As Object
                Set matches = regEx.Execute(lineText)
                If matches.Count > 0 Then
                    rng.Paragraphs(1).Range.Delete
                End If
            End If

            rng.Collapse Direction:=wdCollapseEnd
            rng.MoveStart Unit:=wdCharacter, Count:=1
        Wend
    End With
    
    ActiveDocument.Content.Find.Execute FindText:="^b", ReplaceWith:="", Replace:=wdReplaceAll '刪除分節(jié)符
    ActiveDocument.Content.Find.Execute FindText:="^m", ReplaceWith:="", Replace:=wdReplaceAll '刪除分頁(yè)符
    
End Sub

Sub 刪除分頁(yè)符分節(jié)符4()
    Call 刪除分頁(yè)符4_1
    Call 刪除分節(jié)符4_2
    MsgBox "已刪除所有分頁(yè)符分節(jié)符"
End Sub


Sub 遍歷設(shè)置各級(jí)段落樣式5()
'
'遍歷每個(gè)段落 逐段落進(jìn)行標(biāo)題匹配設(shè)置樣式
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Selection.HomeKey Unit:=wdStory
    Dim t2_reg, t3_reg, t4_reg, t5_reg, t6_reg, t7_reg, cankao_reg
        
    Set t2_reg = CreateObject("vbscript.regexp")
    t2_reg.pattern = "^(第[一二三四五六七八九十 ]+篇[^\r]*)\r"
    Set t3_reg = CreateObject("vbscript.regexp")
    
    Dim para As Paragraph
    Dim isSearched As Boolean
    Dim pos As Long
    For Each para In ActiveDocument.Paragraphs
        '用if-elseif更好-不想改了
        isSearched = False
        If t2_reg.test(para.Range.text) And Not isSearched Then
            isSearched = True
            para.Style = ActiveDocument.Styles(wdStyleHeading2)
            pos = InStr(para.Range.text, "篇") + 1
            para.Range.Characters(pos).InsertBefore " " '此段落一定有篇
        End If
        
    Next
    Selection.HomeKey Unit:=wdStory
    MsgBox "遍歷設(shè)置各級(jí)段落樣式完成"

End Sub

Sub 設(shè)置各級(jí)標(biāo)題樣式5()
'不推薦-慢
'采用正則匹配,然后查找設(shè)置對(duì)應(yīng)的段落格式
'https://devbox.cn/p/Zai_vba_Zhong_di_460e0cc1.html(非對(duì)象不使用set,需要提前Dim聲明,對(duì)象需要set,可不Dim聲明)
'可簡(jiǎn)化成1個(gè)函數(shù),傳參遍歷執(zhí)行-但不想!
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim t2_reg, t3_reg, t4_reg, t5_reg, t6_reg, t7_reg, strA$  '最后1個(gè)$ 只對(duì)strA有效
    strA = ActiveDocument.Content.text
    Set t2_reg = CreateObject("vbscript.regexp")

    '二級(jí)標(biāo)題
    Selection.HomeKey Unit:=wdStory
    t2_reg.pattern = "\r(第[一二三四五六七八九十 ]+篇[^\r]*)\r"
    t2_reg.Global = True
    Set t2_titles = t2_reg.Execute(strA)
    
    For Each t2_title In t2_titles
        With Selection.Find
            .ClearFormatting
            .text = t2_title.SubMatches(0)
            .Execute Forward:=True
        End With
    
        Selection.Style = ActiveDocument.Styles(wdStyleHeading2)
    
        Selection.HomeKey Unit:=wdStory
    Next
    MsgBox "標(biāo)題正文樣式設(shè)置完成"
End Sub


Sub 設(shè)置圖表樣式6()
'
'設(shè)置圖表樣式
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim mytable As Table
    For Each mytable In ActiveDocument.Tables
        With mytable
            .TopPadding = PixelsToPoints(0, True)
            .BottomPadding = PixelsToPoints(0, True)
            .LeftPadding = PixelsToPoints(0, True)
            .RightPadding = PixelsToPoints(0, True)
            .Spacing = PixelsToPoints(0, True)
            .AllowPageBreaks = True
            .AllowAutoFit = True
            With .Rows
                .WrapAroundText = False
                .Alignment = wdAlignRowCenter
                .AllowBreakAcrossPages = False
                .HeightRule = wdRowHeightExactly
                .Height = CentimetersToPoints(0)
                .LeftIndent = CentimetersToPoints(0)
            End With
            
            With .Range
                With .Font
                    .Name = "宋體"
                    .Name = "Times New Roman"
                    .Color = wdColorAutomatic
                    .Size = 7.5
                    .Kerning = 0
                    .DisableCharacterSpaceGrid = True
                End With
                
                With .ParagraphFormat
                    .CharacterUnitFirstLineIndent = 0
                    .FirstLineIndent = CentimetersToPoints(0)
                    .LineSpacingRule = wdLineSpaceSingle
                    .Alignment = wdAlignParagraphCenter
                    .AutoAdjustRightIndent = False
                    .DisableLineHeightGrid = True
                    
                    .LeftIndent = CentimetersToPoints(0)
                    .RightIndent = CentimetersToPoints(0)
                    .FirstLineIndent = CentimetersToPoints(0)
                    .CharacterUnitLeftIndent = 0
                    .CharacterUnitRightIndent = 0
                    .CharacterUnitFirstLineIndent = 0
                End With
                .Cells.VerticalAlignment = wdCellAlignVerticalCenter
            End With

            .PreferredWidthType = wdPreferredWidthPoints
            .PreferredWidth = CentimetersToPoints(14.5)
            With .Borders
                .InsideLineStyle = wdLineStyleSingle
                .OutsideLineStyle = wdLineStyleSingle
                .InsideLineWidth = wdLineWidth025pt
                .OutsideLineWidth = wdLineWidth025pt
                .InsideColor = wdColorAutomatic
                .OutsideColor = wdColorAutomatic
            End With
            
        End With
    Next
    Selection.HomeKey Unit:=wdStory

    Dim ishape As InlineShape
    For Each ishape In ActiveDocument.InlineShapes
        With ishape
            If .Type = wdInlineShapePicture Then
                .LockAspectRatio = msoTrue
                .Width = CentimetersToPoints(14.5)
            End If
        End With
        ishape.Range.Style = ActiveDocument.Styles("圖片樣式")

    Next
    Dim sh As Shape
    For Each sh In ActiveDocument.Shapes
        With sh
            If .Type = msoPicture Then
                .LockAspectRatio = msoTrue
                .Width = CentimetersToPoints(14.5)
            End If
        End With

        With Selection.ParagraphFormat
            .LeftIndent = CentimetersToPoints(0)
            .RightIndent = CentimetersToPoints(0)
            .FirstLineIndent = CentimetersToPoints(0)
        End With
    Next
    
    Selection.HomeKey Unit:=wdStory
    
    MsgBox "圖表樣式設(shè)置完成"

End Sub

Private Sub SetSuperscriptAndSubscript(ByVal PrefixChr As String, ByVal SetChr As String, Optional ByVal PostChr As String, Optional ByVal SuperscriptMode As Boolean = True)
   '程序功能:設(shè)置文檔中特定字符為上標(biāo)或下標(biāo)。
   '參數(shù)說(shuō)明:
   'PrefixChr:必選參數(shù),要設(shè)置為上、下標(biāo)字符之前的字符;
   'SetChr:必選參數(shù),要設(shè)置為上、下標(biāo)的字符;
   'PostChr:必選,但可賦空字符串,若為了界定整個(gè)替換符號(hào)而包含的后綴,防止誤替換,可加此參數(shù)
   'SuperscriptMode:可選參數(shù),設(shè)置為 True 表示將 SetChr 設(shè)置為上標(biāo),設(shè)置為 False 表示將 SetChr 設(shè)置為下標(biāo),默認(rèn)為 True。

   Selection.Start = ActiveDocument.Paragraphs(1).Range.Start
   Selection.Collapse wdCollapseStart
   With Selection.Find
       .ClearFormatting
       .MatchCase = False
       .Replacement.ClearFormatting
       .text = PrefixChr & SetChr & PostChr
       .Replacement.text = .text
       If SuperscriptMode Then
           .Replacement.Font.Superscript = True
       Else
           .Replacement.Font.Subscript = True
       End If
       .Execute Replace:=wdReplaceAll
       .ClearFormatting
       .Replacement.ClearFormatting
       .text = PrefixChr
       If SuperscriptMode Then
           .Font.Superscript = True
       Else
           .Font.Subscript = True
       End If
       .Replacement.text = .text
       If SuperscriptMode Then
           .Replacement.Font.Superscript = False
       Else
           .Replacement.Font.Subscript = False
       End If
       .Execute Replace:=wdReplaceAll
       If Len(PostChr) > 0 Then
           .ClearFormatting
           .Replacement.ClearFormatting
           .text = PostChr
           If SuperscriptMode Then
               .Font.Superscript = True
           Else
               .Font.Subscript = True
           End If
           .Replacement.text = .text
           If SuperscriptMode Then
               .Replacement.Font.Superscript = False
           Else
               .Replacement.Font.Subscript = False
           End If
           .Execute Replace:=wdReplaceAll
       End If
   End With
End Sub


Sub 執(zhí)行上下標(biāo)7()
'
'依靠SetSuperscriptAndSubscript來(lái)實(shí)現(xiàn)
'
    Call SetSuperscriptAndSubscript("O", "+", "", True)
    Call SetSuperscriptAndSubscript("O", "-", "", True)
    
    Call SetSuperscriptAndSubscript("H", "2", "O", False)
    Call SetSuperscriptAndSubscript("TiO", "2", "", False)
    
    MsgBox "設(shè)置上下標(biāo)完成"
End Sub

Sub 數(shù)字智能自動(dòng)排版流程_遍歷段落()
    MsgBox "這種遍歷更快更好-磊磊"
    Call 設(shè)置標(biāo)題正文模板樣式1
    Call 設(shè)置頁(yè)面參數(shù)2
    Call 刪除空白行3
    Call 刪除分頁(yè)符分節(jié)符4
    Call 遍歷設(shè)置各級(jí)段落樣式5
    Call 設(shè)置圖表樣式6
    Call 執(zhí)行上下標(biāo)7
    MsgBox "已全部設(shè)置完成-磊磊"
End Sub

到了這里,關(guān)于word vba自動(dòng)化排版-設(shè)置標(biāo)題模板樣式、標(biāo)題、正文、圖表、頁(yè)面、上下標(biāo)等設(shè)置、刪除空白行、刪除分頁(yè)符分節(jié)符、刪除空格等的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Python辦公自動(dòng)化之Word文檔自動(dòng)化:全網(wǎng)最全,看這一篇就夠了

    Python辦公自動(dòng)化之Word文檔自動(dòng)化:全網(wǎng)最全,看這一篇就夠了

    目錄 一、環(huán)境安裝 1、升級(jí)pip 2、python-docx 3、win32com 4、mailmerge 5、matplotlib 二、Python-docx 新建文檔 三、Python-docx 編輯已存在文檔 四、win32com 將 doc 轉(zhuǎn)為 docx 五、win32com 操作 word 1、打開(kāi)新的word文檔并添加內(nèi)容 2、打開(kāi)已存在word文檔并添加內(nèi)容 3、轉(zhuǎn)換word為pdf 六、Python-docx 操作

    2024年02月01日
    瀏覽(55)
  • Word、Excel、PPT題庫(kù)——“辦公自動(dòng)化”

    Word、Excel、PPT題庫(kù)——“辦公自動(dòng)化”

    小雅蘭期末加油沖沖沖!??! 1. 【單選題】下列文件擴(kuò)展名,不屬于Word模板文件的是( A )。 A. .DOCX B. .DOTM C. .DOTX D. .DOT 本題的考查點(diǎn)是word基本知識(shí)的了解。 ? ? .DOCX:word文檔。 ? ? .DOTM:?jiǎn)⒂煤甑膚ord模板。 ? ? .DOTX:word模板。 ? ? .DOT:word 97-2003模板。 ? ? 故本題答案為

    2024年02月07日
    瀏覽(25)
  • python辦公自動(dòng)化(6)——讀取word文檔

    python辦公自動(dòng)化(6)——讀取word文檔

    因?yàn)槲覀円M(jìn)行文件相關(guān)的操作,所以需要在一開(kāi)始使用import導(dǎo)入Python內(nèi)置的os模塊。 我們需要先獲取該文件夾下所有的答題卡列表,再使用for循環(huán)遍歷文件夾中所有學(xué)生的答題卡,以便之后逐個(gè)讀取信息。 完成了第一個(gè)步驟,接下來(lái),我們就需要在for循環(huán)里,依次獲取每位

    2023年04月08日
    瀏覽(21)
  • python自動(dòng)化辦公——讀取PPT寫(xiě)入word表格

    python自動(dòng)化辦公——讀取PPT寫(xiě)入word表格

    ??由于我們知識(shí)圖譜課程需要將課堂小組匯報(bào)的PPT總結(jié)成word文檔,而我覺(jué)得一頁(yè)一頁(yè)復(fù)制PPT中的內(nèi)容比較麻煩,所以直接安排:讀PPT寫(xiě)word ??需要操作PPT幻燈片和word文檔,所以需要導(dǎo)入docx 和pptx兩個(gè)包 這里我的docx使用的是0.2.4版本 pptx使用的是0.6.21版本供參考 引入os、ppt

    2024年02月11日
    瀏覽(24)
  • Python操作Word:輕松實(shí)現(xiàn)文檔的創(chuàng)建、編輯與自動(dòng)化處理

    引言: 在日常工作和學(xué)習(xí)中,我們經(jīng)常需要使用Microsoft Word來(lái)創(chuàng)建、編輯和處理文檔。然而,手動(dòng)操作Word可能會(huì)耗費(fèi)大量的時(shí)間和精力。為了提高工作效率,我們可以使用Python編程語(yǔ)言來(lái)操作Word文檔,實(shí)現(xiàn)文檔的自動(dòng)化處理。本文將詳細(xì)介紹如何使用Python操作Word,包括創(chuàng)建

    2024年01月21日
    瀏覽(21)
  • Python自動(dòng)化小技巧21——實(shí)現(xiàn)PDF轉(zhuǎn)word功能(程序制作)

    Python自動(dòng)化小技巧21——實(shí)現(xiàn)PDF轉(zhuǎn)word功能(程序制作)

    案例背景 為什么這個(gè)年代PDF轉(zhuǎn)word,某wps居然還要收費(fèi).....很多軟件都可以實(shí)現(xiàn)這個(gè)功能,但是效果都有好有壞,而且有的還付費(fèi),很麻煩。 那就用python實(shí)現(xiàn)這個(gè)功能吧,然后把代碼打包為.exe的程序,這樣隨便在哪個(gè)電腦上都能運(yùn)行,給那些沒(méi)有python環(huán)境的人一個(gè)便利。 代碼

    2024年02月11日
    瀏覽(27)
  • python自動(dòng)化辦公——定制化讀取Excel數(shù)據(jù)并寫(xiě)入到word表格

    python自動(dòng)化辦公——定制化讀取Excel數(shù)據(jù)并寫(xiě)入到word表格

    最近到了畢業(yè)設(shè)計(jì)答辯的時(shí)候,老師讓我?guī)彤厴I(yè)生寫(xiě)一段畢業(yè)設(shè)計(jì)的功能就是提供一個(gè) 學(xué)士學(xué)位授予申請(qǐng)表 ,根據(jù)定制化需求,編寫(xiě)定制化代碼。 docx格式的word如下圖。 再提供一個(gè)Excel表格,要求可以直接讀取表格里的對(duì)應(yīng)內(nèi)容,填入到word表格里的對(duì)應(yīng)位置。表格是我自己

    2024年02月10日
    瀏覽(26)
  • 怎么從休學(xué)證明中取出休學(xué)原因(python自動(dòng)化辦公,涉及word和excel)

    本代碼偏向處理高校教務(wù)處的工作 休學(xué)或請(qǐng)假模板如下: 需求說(shuō)明: 代碼如下: 重要知識(shí)點(diǎn)補(bǔ)充

    2024年02月07日
    瀏覽(22)
  • 接口自動(dòng)化測(cè)試實(shí)踐指導(dǎo)(下):接口自動(dòng)化測(cè)試斷言設(shè)置思路

    接口自動(dòng)化測(cè)試實(shí)踐指導(dǎo)(下):接口自動(dòng)化測(cè)試斷言設(shè)置思路

    作者 : 石臻臻 , CSDN博客之星Top5 、 Kafka Contributor 、 nacos Contributor 、 華為云 MVP , 騰訊云TVP , 滴滴Kafka技術(shù)專家 、 KnowStreaming 。 KnowStreaming 是滴滴開(kāi)源的Kafka運(yùn)維管控平臺(tái), 有興趣一起參與參與開(kāi)發(fā)的同學(xué),但是怕自己能力不夠的同學(xué),可以聯(lián)系我,當(dāng)你導(dǎo)師帶你參與開(kāi)源! 。 在

    2024年01月18日
    瀏覽(30)
  • python從小白到大師-第一章Python應(yīng)用(八)應(yīng)用領(lǐng)域與常見(jiàn)包-自動(dòng)化辦公word

    目錄 一.python-docx 二.pypiwin32 Python-docx是一個(gè)用于創(chuàng)建、修改和讀取Microsoft Word文件(.docx)的Python庫(kù)。它提供了一組豐富的功能,使開(kāi)發(fā)人員能夠使用Python生成自定義的Word文檔。 以下是python-docx庫(kù)的一些主要特點(diǎn)和功能: 創(chuàng)建和編輯Word文檔:可以使用python-docx庫(kù)創(chuàng)建新的Wor

    2024年02月21日
    瀏覽(19)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包