WORD VBA 每一页第一段文字

本文介绍了一种使用VBA脚本自动化处理Word文档的方法,包括遍历所有页码,检查特定字体和大小的段落,并进行格式调整。此过程涉及字体名称、大小的检查以及页面的插入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

'所有页码

pages = ActiveDocument.ActiveWindow.Panes(1).Pages.Count
   For i = 1 To pages

      '下一页,选中
       ActiveDocument.GoTo(wdGoToPage, wdGoToAbsolute, i).Select
        p = Selection.Information(wdActiveEndPageNumber) '当前页码
        
        ‘所在页第一段选中
         ActiveDocument.Bookmarks("\page").Range.Paragraphs.Item(1).Range.Select
         
        ‘字体
         font_name = ActiveDocument.Bookmarks("\page").Range.Paragraphs.Item(1).Range.Font.Name
        ’大小
         font_size = ActiveDocument.Bookmarks("\page").Range.Paragraphs.Item(1).Range.Font.Size
        ‘内容
         txt = ActiveDocument.Bookmarks("\page").Range.Paragraphs.Item(1).Range.Text
         
        If font_name = "黑体" Then
            If font_size = 16 Then
            
                 Selection.InsertNewPage
                 i = i + 1
                 
    If bl = False Then
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    End If
    
    
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="*****"
    
    
            End If
        End If
        

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值