Sub AdjustPicWidthAndHeight()
'
' AdjustPicWidthAndHeight Macro
' 宏在 2014/4/23 由 admin 创建
'
'AdvertisePublishAs 宏
' 将广告发布导出为 PDF 和 XPS
'Sub setpicsize() '设置图片大小
Dim n '图片个数
Dim KuanDu As Double '定义图片宽度
Dim GaoDu As Double '定义图片高度
Dim Ratio1 As Double
Dim Ratio2 As Double
On Error Resume Next '忽略错误
KuanDu = 10 '图片宽度,单位为厘米
KuanDu = KuanDu * 28.3446712 '将厘米转换为像素
For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes类型图片
picheight = ActiveDocument.InlineShapes(n).Height
picwidth = ActiveDocument.InlineShapes(n).Width
Ratio1 = KuanDu / picwidth
'Ratio2 = GaoDu / picheight
ActiveDocument.InlineShapes(n).LockAspectRatio = msoFalse '不锁定图片的纵横比
'ActiveDocument.InlineShapes(n).Height = 320 '设置图片高度为 320px
ActiveDocument.InlineShapes(n).Width = KuanDu '设置图片宽度 425px
ActiveDocument.InlineShapes(n).Height = picheight * Ratio1
ActiveDocument.InlineShapes(n).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next n
For n = 1 To ActiveDocument.Shapes.Count 'Shapes类型图片
picheight = ActiveDocument.InlineShapes(n).Height
picwidth = ActiveDocument.InlineShapes(n).Width
Ratio1 = KuanDu / picwidth
'Ratio2 = GaoDu / picheight
ActiveDocument.InlineShapes(n).LockAspectRatio = msoFalse '不锁定图片的纵横比
' ActiveDocument.Shapes(n).Height = 320 '设置图片高度为 320px
ActiveDocument.Shapes(n).Width = KuanDu '设置图片宽度 425px
ActiveDocument.InlineShapes(n).Height = picheight * Ratio1
ActiveDocument.InlineShapes(n).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next n
End Sub
阅读(907) | 评论(0) | 转发(0) |