Word VBA-图片操作汇总

==========================

Sub 图片后加回车()
	Dim s As Shape
	Dim pg As Paragraph
	
	'先将图片批量转换为嵌入型
	For Each s In ActiveDocument.Shapes
	    With s
	        If s.Type = msoPicture Then
	            s.ConvertToInlineShape
	        End If
	    End With
	Next s
	
	'遍历所有段落
	For Each pg In ActiveDocument.Paragraphs
	    '计算段落内的图片数量
	    pgCount = pg.Range.InlineShapes.Count
	    If pgCount > 0 Then
	        With pg
	            .Range.Select
	            Selection.MoveUp unit:=wdParagraph, Extend:=wdMove
	            Selection.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdMove
	            Selection.InsertAfter Chr(13)
	        End With
	    End If
	Next pg

End Sub

==========================

Sub 批量设置图片大小()
    
    Dim n, m
    Dim blnisinlineshape As Boolean
    Dim mylineshape As InlineShape
    
    On Error Resume Next '忽略错误
    
    m = ActiveDocument.InlineShapes.Count
    
    For n = 1 To 2 'inlineshapes类型的图片
    ActiveDocument.InlineShapes(n).LockAspectRatio = msoFalse '不锁定图片的纵横比
    ActiveDocument.InlineShapes(n).Height = 153 '设置图片高度为 243px
    ActiveDocument.InlineShapes(n).Width = 243 '设置图片高度为153px
    Next n
    
    For n = 1 To 2 'inlineshapes类型的图片
    ActiveDocument.Shapes(n).LockAspectRatio = msoFalse '不锁定图片的纵横比
    ActiveDocument.Shapes(n).Height = 153 '设置图片高度为 153px
    ActiveDocument.Shapes(n).Width = 243 '设置图片高度为243px
    Next n
    
    For n = 3 To m 'inlineshapes类型的图片
    ActiveDocument.InlineShapes(n).LockAspectRatio = msoFalse '不锁定图片的纵横比
    ActiveDocument.InlineShapes(n).Height = 297 '设置图片高度为 297px
    ActiveDocument.InlineShapes(n).Width = 405 '设置图片高度为405px
    Next n
    
    For n = 3 To m 'inlineshapes类型的图片
    ActiveDocument.Shapes(n).LockAspectRatio = msoFalse  '不锁定图片的纵横比
    ActiveDocument.Shapes(n).Height = 297 '设置图片高度为 297px
    ActiveDocument.Shapes(n).Width = 405 '设置图片高度为405px
    Next n

    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 50
        .SpaceBeforeAuto = False
        .SpaceAfter = 50
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(3)
        .Alignment = wdAlignParagraphCenter
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 10
        .LineUnitAfter = 10
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
      End With

End Sub


==========================

==========================

==========================

==========================

==========================

==========================

==========================

==========================

==========================

==========================

 

 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值