1、插入图片的同时显示图片名称Sub InsertPic()Dim myfile As FileDialogSet myfile = Application.FileDialog(msoFileDialogFilePicker)With myfile.InitialFileName = “F:“If .Show = -1 ThenFor Each fn In .SelectedItemsSet mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True)按比例调整相片尺寸WidthNum = mypi
2、c.Widthc = 10 在此处修改相片宽,单位厘米mypic.Width = c * 28.35mypic.Height = (c * 28.35 / WidthNum) * mypic.HeightIf Selection.Start = ActiveDocument.Content.End - 1 Then 如光标在文末Selection.TypeParagraph 在文末添加一空段ElseSelection.MoveDownEnd IfSelection.Text = Basename(fn) 函数取得文件名Selection.EndKeyIf Selection.Start = A
3、ctiveDocument.Content.End - 1 Then 如光标在文末Selection.TypeParagraph 在文末添加一空段ElseSelection.MoveDownEnd IfNext fnElseEnd IfEnd WithSet myfile = NothingEnd SubFunction Basename(FullPath) 取得文件名Dim x, yDim tmpstringtmpstring = FullPathx = Len(FullPath)For y = x To 1 Step -1If Mid(FullPath, y, 1) = “ Or _Mid
4、(FullPath, y, 1) = “:“ Or _Mid(FullPath, y, 1) = “/“ Thentmpstring = Mid(FullPath, y + 1)Exit ForEnd IfNextBasename = Left(tmpstring, Len(tmpstring) - 4)End Functionword 批量修改图片大小 固定长宽篇这部分要说的是把 word 中的所有图片修改成固定的并且相同的长和宽!1、打开 word,工具宏宏(或者直接按 Alt+F8)进入宏的界面,如下面所示,输入一个宏名,宏名自己起,能记住就行!2、宏名起好了,单击“创建”进入 Visu
5、al Basic 编辑器,输入如下代码并保存Sub setpicsize() 设置图片大小Dim n 图片个数On Error Resume Next 忽略错误For n = 1 To ActiveDocument.InlineShapes.Count InlineShapes 类型图片ActiveDocument.InlineShapes(n).Height = 400 设置图片高度为 400pxActiveDocument.InlineShapes(n).Width = 300 设置图片宽度 300pxNext nFor n = 1 To ActiveDocument.Shapes.Cou
6、nt Shapes 类型图片ActiveDocument.Shapes(n).Height = 400 设置图片高度为 400pxActiveDocument.Shapes(n).Width = 300 设置图片宽度 300pxNext nEnd Sub3、返回 word,工具宏宏(或者直接按 Alt+F8) ,再次进入宏的界面,选择刚才编辑好的宏,并单击“运行” 按钮,就可以了!(图片多时,可能会花一些时间)word 批量修改图片大小 按比例缩放篇这部分要说的是把 word 中的所有图片按比例缩放!具体操作同上,只是代码部分稍做修改,代码如下:Sub setpicsize() 设置图片大小D
7、im n 图片个数Dim picwidthDim picheightOn Error Resume Next 忽略错误For n = 1 To ActiveDocument.InlineShapes.Count InlineShapes 类型图片picheight = ActiveDocument.InlineShapes(n).Heightpicwidth = ActiveDocument.InlineShapes(n).WidthActiveDocument.InlineShapes(n).Height = picheight * 1.1 设置高度为 1.1 倍ActiveDocument
8、.InlineShapes(n).Width = picwidth * 1.1 设置宽度为 1.1 倍Next nFor n = 1 To ActiveDocument.Shapes.Count Shapes 类型图片picheight = ActiveDocument.Shapes(n).Heightpicwidth = ActiveDocument.Shapes(n).WidthActiveDocument.Shapes(n).Height = picheight * 1.1 设置高度为 1.1 倍ActiveDocument.Shapes(n).Width = picwidth * 1.1 设置宽度为 1.1 倍Next nEnd Sub