word中几个好用的宏代码(立方米上标、关闭样式自动更新、删除无效样式、表格加粗边框、宋体引号)

时间:2024-01-18 13:33:32
 Sub 替换立方米()
With Selection.Find
.Text = "m3"
.Replacement.Text = "mm3"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find.Replacement.Font
.Superscript = True
.Subscript = False
End With
With Selection.Find
.Text = "m3"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub '关闭样式自动更新
Sub CloseAutoUpdates()
Dim update As Style
Set Updates = ActiveDocument.Styles
For Each update In Updates
If update.Type = wdStyleTypeParagraph Then
update.AutomaticallyUpdate = False
End If
Next
End Sub Sub 删除无效样式()
For Each objStyle In ActiveDocument.Styles
On Error Resume Next
If objStyle.BuiltIn = False And objStyle.InUse = True Then
objStyle.Delete
End If
Next
End Sub
Sub 表格加粗边框()
'
' 表格加粗边框 宏
' 设置表格加粗边框
'
With Selection.Tables()
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth150pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
Sub 宋体引号()
'
' 宋体引号 宏
' 把所有引号改为宋体
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW() & ChrW() & "]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Replacement.Font.Name = "宋体"
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

使用时打开word,按alt+f11,粘贴上去,要用哪个就把鼠标点到哪个sub里,然后f5,搞定!

PS:以上有些是网上别人的,有的是我自己录制的,具体记不清了。如有冒犯,请通知我删除!