如何用VBA设置WORD文档的题目(即第一段)的格式

具体要求:第一段即文档题目,去除段前空格,字体为“黑体”,字号为“小二”,加粗,居中对齐,请用VBA代码,千万不要用菜单命令操作。正文格式不变。... 具体要求:第一段即文档题目,去除段前空格,字体为“黑体”,字号为“小二”,加粗,居中对齐,请用VBA代码,千万不要用菜单命令操作。正文格式不变。 展开
 我来答
再见图安7
2015-06-10 · TA获得超过1632个赞
知道小有建树答主
回答量:797
采纳率:0%
帮助的人:568万
展开全部
Sub 宏1()
    Dim str As String, i As Integer, j As Integer
    j = 0
    str = Application.ActiveDocument.Paragraphs(1).Range.Text
    For i = 1 To Len(str)
        If Mid(str, i, 1) = " " Then
        Else
            Exit For
        End If
        j = j + 1
    Next
    str = Right(str, Len(str) - j)
    Application.ActiveDocument.Paragraphs(1).Range.Text = str
    Application.ActiveDocument.Paragraphs(1).Range.Select
    Selection.Font.Name = "黑体"
    Selection.Font.Size = 18
    Selection.Font.Bold = wdToggle
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub
更多追问追答
追问
高手!
能不能在您提供的代码后再加上正文设置代码?
正文(即第二段以后)格式:每段首行缩进2字符,字体为“仿宋-GB2312",字号为“小三”,每段首行是:一 二三四五六七八九十或(一)(二)(三)(四)(五)(六)(七)(八)(九)(十)或1 2 3 4 5 6 7 8 9 10等字符要加粗

万分期待
追答
Sub test()
With Application.ActiveDocument
Dim i, pcount As Integer, astr As String
pcount = .Paragraphs.Count
For i = 2 To pcount
astr = Left(.Paragraphs(i).Range.Text, 1)
Select Case astr
Case "1" To "9", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"
.Paragraphs(i).Range.Select
Selection.MoveLeft (1)
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Bold = True
Case "("
If Mid(.Paragraphs(i).Range.Text, 3, 1) = ")" Then
Select Case Mid(ActiveDocument.Paragraphs(i).Range.Text, 2, 1)
Case "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"
.Paragraphs(i).Range.Select
Selection.MoveLeft (1)
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Font.Bold = True
End Select
End If
End Select
Next
.Paragraphs(2).Range.Select
End With
With Selection
.MoveLeft (1)
.EndKey Unit:=wdStory, Extend:=wdExtend
.Font.Size = 15
.ParagraphFormat.CharacterUnitFirstLineIndent = 2
.Font.Name = "仿宋-GB2312"
End With
End Sub
博思aippt
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT... 点击进入详情页
本回答由博思aippt提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式