创建宏函数的方式:
点开以后点击查看宏:
在箭头位置输入要创建的宏函数的名字,然后点击创建
在方框位置输入你需要的代码然后点击绿色三角编译运行就可以了。
如果编译没出错,就可以查看当前文档观察结果,结果成功的话下次可以直接在查看宏页面选中相应函数名点击运行就可以了
下面分享一些写论文我觉得很方便的宏函数:
一:图片居中宏函数:
Sub CenterAllPictureParagraphs()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
'检查是否是一个图片对象。排除其他的内联形状,如文本框等。
If pic.Type = wdInlineShapePicture Then
'将当前图片所在段落设置为居中对齐格式
pic.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End If
Next pic
End Sub
二:删除文档中所有空格的宏函数:
Sub RemoveSpaces()
'
' RemoveSpaces 宏
'
'
'定义变量
Dim strText As String
Dim i As Integer
'获取文档内容
strText = ActiveDocument.Range.Text
'循环遍历文本字符
For i = Len(strText) To 1 Step -1
'如果是空格则删除
If Mid(strText, i, 1) = " " Then
strText = Left(strText, i - 1) & Mid(strText, i + 1)
End If
Next i
'替换文本
ActiveDocument.Range.Text = strText
End Sub