WORD批量更改所有图片大小

好代码,当然不能只知道收藏,分享给需要的朋友。摘录请注明:

引自:http://miaozk2006.blog.163.com/blog/static/38247058201372684539815/

1、WORD中首先把某待转的某一图片调整到要求的大小,点击这张自己设定的样本图片,打开宏编辑器,拷入下列代码。直接运行即可。

注明:本代码摘息网络,调试测试通过。

Sub 按选择的图片样本设置图片大小()
    Dim s
    Dim r, SelectShape As Boolean
    If Selection.InlineShapes.Count = 1 Then
        SelectShape = True
    ElseIf Selection.ShapeRange.Count = 1 Then

        SelectShape = True
    End If

    If SelectShape And Selection.InlineShapes.Count = 1 Then
        Set s = Selection.InlineShapes(1)
        r = Array(s.Height, s.Width)
    ElseIf SelectShape Then
        Set s = Selection.ShapeRange(1)
        r = Array(s.Height, s.Width)
    End If
    If SelectShape Then
        For Each s In ActiveDocument.InlineShapes
            s.Height = r(0)
            s.Width = r(1)
        Next s
        For Each s In ActiveDocument.Shapes
            If InStr(s.Name, "Picture") > 0 Then
                s.Height = r(0)
                s.Width = r(1)
            End If
        Next s
        MsgBox "已经完成对图片大小的设置"
    Else
        MsgBox "没有选定样本图片"
    End If
End Sub

 

2、在宏代码更改图片的大小,进行全文批量设置。具体代码如下:

Sub FormatPics()
    Dim iSha As InlineShape
    For Each iSha In ActiveDocument.InlineShapes
        If iSha.Type = wdInlineShapePicture Then
              iSha.LockAspectRatio = msoFalse      '不锁定纵横比
            iSha.Width = CentimetersToPoints(16) '宽5CM
            iSha.Height = CentimetersToPoints(24.5) '高5CM
        End If
    Next
End Sub

相关参考

VBA语言基础

各种Excel VBA的命令

VB6 中将数据导出到 Excel 提速之法

VBA语法200

各种Excel VBA的命令

Execl编程详解

  VB

 VB软件操作EXCELVB全面控制Excel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 如果你想在Word批量处理图片大小,可以使用宏命令来实现。首先打开Word文档,选择视图菜单中的查看宏命令,然后创建一个新的宏。在宏中输入相应的代码,代码可以根据你的实际需求进行修改。接下来,点击窗口上方的运行按钮(快捷键F5),即可批量修改Word文档中所有图片的大小。这种方法特别适用于将Word转换为PDF文件时,如果在转换之前不调整图片大小以适应页面大小,最终导出的PDF文档中的图片可能会因尺寸过大而超出页面范围,导致图片显示不完整。\[3\] #### 引用[.reference_title] - *1* *3* [pands 画图 调整大小_用宏命令对word里的图片尺寸大小进行批量修改的方法](https://blog.csdn.net/weixin_39527078/article/details/109987708)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [如何批量压缩图片大小?教你3个批量压缩图片的方法](https://blog.csdn.net/m0_71314894/article/details/127410847)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值