Word 图片操作
2015-08-20 11:36
1096 查看
一. 一张一张的处理
</pre><pre name="code" class="vb">Sub 插入图片() Dim myfile As FileDialog Set myfile = Application.FileDialog(msoFileDialogFilePicker) With myfile .InitialFileName = "D:\" If .Show = -1 Then For Each fn In .SelectedItems Set mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True) mypic.Width = 28.345 * 6.3 '根据需要设置 mypic.Height = 28.345 * 5.4 Next fn End If End With Set myfile = Nothing End Sub
二. 在表格中插入图片并根据单元格大小自动改变图片大小
Public Sub ResizeThePicture() On Error Resume Next Dim picW As Single, picH As Single Dim cellW As Single, cellH As Single Dim rtoW As Single, rtoH As Single cellW = ActiveCell.Width cellH = ActiveCell.Height picW = Selection.ShapeRange.Width picH = Selection.ShapeRange.Height rtoW = cellW / picW * 0.95 rtoH = cellH / picH * 0.95 If rtoW < rtoH Then Selection.ShapeRange.ScaleWidth rtoW, msoFalse, msoScaleFromTopLeft Else Selection.ShapeRange.ScaleHeight rtoH, msoFalse, msoScaleFromTopLeft End If picW = Selection.ShapeRange.Width picH = Selection.ShapeRange.Height Selection.ShapeRange.IncrementLeft (cellW - picW) / 2 Selection.ShapeRange.IncrementTop (cellH - picH) / 2 End Sub
三. 批量同时处理相同大小
Sub 图片大小处理() Dim iSha As InlineShape For Each iSha In ActiveDocument.InlineShapes If iSha.Type = wdInlineShapePicture Then iSha.LockAspectRatio = msoFalse iSha.Width = CentimetersToPoints(4.6) iSha.Height = CentimetersToPoints(4.2) End If Next End Sub
四. 此法针对一个word文档表中有多种尺寸大小的图片
4.1 首先,用如运行如下的代码对前部分相同的图片进行处理Sub 图片处理一() Mywidth = 5.21 '5.21为图片宽度(厘米) Myheigth = 3.92 '3.92为图片高度(厘米) For Each iShape In ActiveDocument.InlineShapes iShape.Height = 28.345 * Myheigth '1cm等于28.35px iShape.Width = 28.345 * Mywidth '1cm等于28.35px Next iShape End Sub
Sub 图片大小处理二() ' 批量设置图片尺寸 ' 设置好第一张整改图片(假设整改图片位于整个文档图片第k位)的大小之后,运行此宏即可. Dim n For n = k + 1 To ActiveDocument.InlineShapes.Count '注:k+1表示第二张整改图片,实际操作中要填入实际数值 ActiveDocument.InlineShapes(n).Width = ActiveDocument.InlineShapes(k).Width 'k表示第一张整改图片,实际操作中要填入实际数值 ActiveDocument.InlineShapes(n).Height = ActiveDocument.InlineShapes(k).Height 'k表示第一张整改图片,实际操作中要填入实际数值 Next n End Sub
转自: http://needzc.vicp.net/thread-83-1-1.html
相关文章推荐
- 不借助 Wine 和云服务:新项目能让 Linux 完整运行微软 Office 套件
- Outlook 批量发送邮件
- WPS Office:Linux 上的 Microsoft Office 的免费替代品
- [软件咨询]WPS2012正式版已发布 金山Office移动版4.0发布
- excel vba 限制工作表的滚动区域代码
- excel vba 高亮显示当前行代码
- 用Coldfusion生成 OFFICE 文件的代码
- 重现 Office 2007 中的菜单和工具栏的方法
- Office Word九条常用技巧
- Microsoft Office 2007 SP1 简体中文正式版 升级包官方下载地址
- 官方 WPS office 2005 个人精装版 下载
- VBA中连接SQLSERVER数据库例子
- 在office Word中任意选中单词某一部分字母
- Office 2007 System 常见问题集第1/3页
- Microsoft Office 2007 全系列迅雷下载
- QQ聊天记录格式化的word宏第二版
- 永中迎破产清算,叫板微软终成追忆
- 让source insight 搜索到.S的文件 高亮AT&T ASM 文件keyword的方法 sourceinsight技巧
- 解决Office 2010 激活问题。
- Office 2007的照相机功能增加