Word 中几个较有用的宏

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

你可能感兴趣的:(office,WORD,宏,纯文本粘贴,编辑器)