str = Right(str, Len(str) - 1) If(str ="SEQ 图 \* ARABIC")Then 'MsgBox ("找到域") '找到域的位置后,相当于光标定位到行,按End键,光标到最后,在Ctrl+Home,全选此行,再更改样式 aField.Select Selection.EndKey Unit:=wdLine Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Selection.Style...
你在第一个SUB中打开文件,如果“SUB 分辨页数”不需要多次被调用干脆就在第一个SUB中每行IF调用一个函数。“SUB 分辨页数”使用IF...THEN...END IF 就可以了,不需要用ELSE,因为它每在逻辑上并不需连续。
'do something with it. We will just display 'paragraph text if its style is "Heading 4" If oPara.Style = "标题 1" Then 'If oPara.Style = "正文" Then MsgBox oPara.Range.Text End If Next oPara End Sub 【分享成果,随喜正能量】我20多年的VBA实践经验,全部浓缩在下面的各个教程中: 【...
Call 设置副标题格式(ActiveDocument.Paragraphs(2)) '公文:如果标题的下一行多于1个字符(换行符算1个字符),那么就插入一空行,否则不用。 If Len(ActiveDocument.Paragraphs(2).Next.Range.Text) > 1 Then ActiveDocument.Paragraphs(2).Range.InsertParagraphAfter '在当前文档的第一段之后插入一个新段落 End If El...
Excel VBA 操作 Word(入门篇) 原文地址 本文的对象是:有一定Excel VBA基础,对Word VBA还没有什么认识,想在Excel中通过VBA操作Word还有困难的人。 一、新建Word引用 需要首先创建一个对 Word Application 对象的引用。在VBA中,工具-引用,选取“MicroSoft Word 11.0 Object Library”。
If Selection.Type <> wdSelectionIP Then Selection.Font.Bold = True Else MsgBox "You need to select some text." End If 5)文件开头 Beginning of document: Selection.HomeKey Unit:=wdStory, Extend:=wdMove 6)当前行的开头: Beginning of current line: ...
If InStr(1, 所有字体, 字体类型) = 0 Then 所有字体 = 所有字体 & 字体类型 & vbLf End If Next Next 获得字体 = 所有字体 End Function 接下来按F5运行,或者关闭vb窗口后,按alt+f8运行这个宏 等待片刻后,会生成一个新的文档,在新的word文档中,会列出刚才的word中使用的所有字体 xml法 其实word的...
1 打开一个word文档,然后按快捷键alt+f8弹出“宏”对话框。2 在宏名中输入名称“printfile”,然后单击“创建”按钮。3 弹出VBA编辑器,在编辑器的中间是代码窗口,将代码窗口中的代码清除。4 在代码窗口输入新的代码:Sub PrintFile()pass$ = InputBox("请输入打印密码:")If pass$ = "abcd" ThenDialogs(...
If Len(i.Range) = 1 Then i.Range.Delete '删除空行 Next For x = 1 To ActiveDocument.Paragraphs.Count ActiveDocument.Paragraphs(x).Range.Text = Trim(ActiveDocument.Paragraphs(x).Range.Text) If x = 1 Then 'ActiveDocument.Paragraphs(x).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter Activ...
str = str & rng.Text str = str & vbTab i = i + 1 '每行8个词 If (i Mod 8) = 0 Then str = str & vbCrLf End If Next rng MsgBox str 结果如下图4所示。 图4:上图1所选文本中词和字符的分析结果 可以看出,Word VBA将符号作为一个词。