Sub 文本粘贴1()
'ctrl+1
'用于粘贴纯文本
Selection.PasteAndFormat (wdFormatPlainText)
End Sub
Sub 文本粘贴2()
'ctrl+2
'用于粘贴从一般新闻网页中复制下来的文本,会自动去除多余的制表符和双行符。
Selection.PasteAndFormat (wdFormatPlainText)
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub 重新排版()
'strl+3
'去除图像转文字带来的多余回车符。事先须在正确的回车符后而加入“##”串。
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "##"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
图像裁切和大小调整
Sub 宏1()
'
' 宏1 宏
'
'
Dim n
On Error Resume Next
'For n = 1 To ActiveDocument.InlineShapes.Count
For n = 1 To 3
ActiveDocument.InlineShapes(n).PictureFormat.CropTop = 100
ActiveDocument.InlineShapes(n).PictureFormat.CropBottom = 50
ActiveDocument.InlineShapes(n).PictureFormat.CropLeft = 75
ActiveDocument.InlineShapes(n).PictureFormat.CropRight = 75
ActiveDocument.InlineShapes(n).ScaleHeight = 95
'ActiveDocument.InlineShapes(n).ScaleWidth = 95
Next n
End Sub
A4扫描为jpg后导入word时将四个页边距均调整为0.43,再执行如下宏
Sub 宏1()
Dim n
On Error Resume Next
For n = 1 To ActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes(n).PictureFormat.CropTop = 10
ActiveDocument.InlineShapes(n).PictureFormat.CropBottom = 10
ActiveDocument.InlineShapes(n).PictureFormat.CropLeft = 10
ActiveDocument.InlineShapes(n).PictureFormat.CropRight = 10
ActiveDocument.InlineShapes(n).ScaleHeight = 100
ActiveDocument.InlineShapes(n).ScaleWidth = 100
Next n
End Sub
这段代码展示了如何使用VBA在Word中实现文本粘贴和格式处理的自动化。`文本粘贴1`和`文本粘贴2`分别处理不同来源的文本,去除多余格式。`重新排版`用于清理图像转换的文字格式。`宏1`则对图片进行裁剪和尺寸调整。这些宏适用于批量处理文档,提高效率。

4036

被折叠的 条评论
为什么被折叠?



