100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Word 利用 VBA 批量设置图片格式

Word 利用 VBA 批量设置图片格式

时间:2018-06-30 07:30:21

相关推荐

Word 利用 VBA 批量设置图片格式

Word 利用 VBA 批量设置图片格式

批量设置图片格式转为嵌入式图形参考资料

批量设置图片格式

Sub setShapeStyle() On Error Resume Next Dim myShape As InlineShape' 如果没有名叫“图片”的样式,提示用户创建Dim imgStyle As Style, imgStyleName As StringimgStyleName = "图片"Set imgStyle = ActiveDocument.Styles(imgStyleName)If imgStyle Is Nothing ThenMsgBox "请先创建样式【" & imgStyleName & "】"Exit SubEnd If'关闭屏幕更新,提升执行效率Application.ScreenUpdating = False'遍历所有嵌入式图片For Each myShape In ActiveDocument.InlineShapesWith myShape' -------- 设置边框 --------.Borders.OutsideLineStyle = wdLineStyleSingle '边框类型.Borders.OutsideColorIndex = wdBlack '边框颜色.Borders.OutsideLineWidth = wdLineWidth100pt '边框粗细' -------- 设置样式 --------If .Type = wdInlineShapePicture Then.Range.Style = imgStyleName '设置图片样式为“图片”End If' -------- 设置高宽 --------.ScaleWidth = 100 ' 缩放重置为100%.ScaleHeight = 100 ' 缩放重置为100%.LockAspectRatio = msoTrue ' 锁定纵横比'.Height = 600 ' 600点'.Width = CentimetersToPoints(15) '15 CM.Width = ThisDocument.PageSetup.TextColumns.Width ' 当前文档宽度' -------- 图片下方插入题注 --------.Range.InsertCaption Label:="图:", TitleAutoText:="", Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0End WithNext'开启屏幕更新Application.ScreenUpdating = TrueEnd Sub

转为嵌入式图形

网上抄来改了一下:

Sub ConvertToInlineShape()Dim total, countcount = 0total = 0For Each myShape In ActiveDocument.ShapesIf myShape.Type = msoPicture Then' 转换为嵌入式图片myShape.ConvertToInlineShapecount = count + 1End Iftotal = total + 1Next myShapeMsgBox "转换【" & count & "/" & total & "】个图片!"End Sub

参考资料

微软Docs 》Office VBA 参考 》Word 》对象模型 》Style 对象

Docs 》Office VBA 参考 》Word 》对象模型 》Range 对象 》方法 》插入题注InsertCaption

WdLineWidth 枚举

Docs》Office》VBA》参考》Word》对象模型》InlineShape》对象》方法》Reset

VBA操作WORD(五)批量调整图片大小、居中设置

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。