with sheet1.shapes("图片 1")
.select
with selection
.top=a.top
.left=a.left
.width=a.width
.height=a.height
end with
end with
图片名 就是图片 1 图片 2 ……
在word中用VBA挑选图片所在的页码
Sub test()
For Each i In ActiveDocument.InlineShapes
i.Select
MsgBox Selection.Information(wdActiveEndPageNumber)
Next
End Sub
如何运用vba将指定图片插入word中?
例如,新建一个4行1列的表格,然后在Cell(3, 1)内插入图片:
Sub Macro1()
Dim mysel
mysel = ActiveDocument.Tables(1).Cell(3, 1)
mysel.InlineShapes.AddPicture FileName:="C:\a.jpg", LinkToFile:=True, SaveWithDocument:=True
End Sub
请教Word中如何用VBA 将所有图片加上边框
只要一句代码?那就给你一句参考一下吧:picCount = ActiveDocument.InlineShapes.Count '计算文件中图片数目在Word中,插入的图片已被转化为 InlineShape 对象。之后用For循环语句,给所有图片加黑色边框。单个图片加边框的语句,你自己可以录制一个宏看看,将录制的宏代码拷贝到For循环中修改一下即可。
___________________________________________________________________
单个图片加边框,你自己录制宏就可以看到代码了,这是学习VBA的必由之路啊。选中一张图片,工具-宏-录制新宏,然后,格式-边框和阴影,给图片加上黑边框,然后,alt+F11打开VB编译器,就看到代码了。本想只授人以渔即足够了,但犹豫了一下,还是贴给你吧:
With Selection.InlineShapes(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
计算图片数目是为了For循环用的,有多少图片就要循环多少次,给所有图片都加上边框。
For i = 1 to picCount
......
Next i
中间就是上面那段代码,把InlineShapes(1)改为InlineShapes(i)
如何用vba取得一个word文件中的所有的图片
提供网上示例代码供参考(此代码的思路是遍历 word 文档中的 Shapes ,缩放到原始图片尺寸,再转粘贴到 Excel 中,借用 Excel 的 ChartObjects 提供的导出功能实现图片原样导出):
Subtest()Rem工具--引用--勾选MicrosoftExcelx.xObjectLibrary..
DimmyshapeAsObject,ExcelAppAsNewExcel.Application
DimExcelAsWorkbook,i%,z%
SetExcel=ExcelApp.Workbooks.Add
ForEachmyshapeInActiveDocument.InlineShapes
Ifmyshape.Type=3Then
i=i+1
myshape.Select
Setmyshape=myshape.ConvertToShape
Rem以下代码将图片以原始比例展示
Withmyshape
.ScaleHeight1,True,msoScaleFromMiddle
.ScaleWidth1,True,msoScaleFromMiddle
EndWith
Selection.Copy
WithExcel.ActiveSheet.ChartObjects.Add(0,0,myshape.Width,myshape.Height).Chart
.Paste
.ExportActiveDocument.Path&""&i&".png"
.Parent.Delete
EndWith
EndIf
Next
Excel.CloseFalse
ExcelApp.Quit
EndSub
word中使用vba按照现在图片的顺序,用新的图片把旧图片全部替换,图片名称统一由规定的
解题思路很重要,下面给出替换图片的关键代码:
Sub替换活动文档中的第一张图片()ActiveDocument.InlineShapes(1).Select
Selection.InlineShapes.AddPicture"[要替换的图片的完整路径]"
EndSub
PS:实际使用中可以将要替换的新图片按照 Word 文档中的图片出现的顺序进行编号(如1.jpg、2.jpg、3.jpg...)并放入一个文件夹中,然后将上述代码放入循环语句中并稍作修改,通过遍历 Word 文档中的 InlineShapes 对象同时传递图片的完整路径即可实现全部替换!
在word中如何用VBA实现插入多张图片
要从两个方面考虑:
1、如何把现有文档中的图片导出?这个代码片断可以参考一下:
Set ImageStream = CreateObject("ADODB.Stream")
With ImageStream
.Type = 1
.Open
.Write ActiveDocument.InlineShapes(1).Range.EnhMetaFileBits
.SaveToFile "d:\Temp\Output.bmp"
.Close
End With
Set ImageStream = Nothing
2、如何把已经到处的图片导入到新文档中?这个函数调用可以参考一下:
ActiveDocument.InlineShapes.AddPicture
如果还是不明白的话,请补充提问。
_____
补充:
请问楼主你运行那个代码片断得到的*完整*错误信息是什么?报错的时候,系统一般会把光标移动到出错的那行代码上,你看到的是哪一行代码出错呢?
我看你贴上来的代码应该是没有什么语法上的错误,“Exit For”的确是不应该要的,但那也不是语法错误啊。
转载请注明出处51数据库 » wordvba图片位置 通过vba设置图片位置