以下内容,是通过VBA来设置Word文档中的图片的格式,即VBA设置图片属性的代码。
一、旋转图片
Dim blnIsInlineShape As Boolean If Selection.Type = wdSelectionInlineShape Then blnIsInlineShape = True Selection.InlineShapes(1).ConvertToShape End If Dim intTurn As Integer intTurn = InputBox("请输入图形要旋转的角度值" & vbCrLf & "正数表示顺时针,负数表示逆时针。", "图形旋转", 30) Selection.ShapeRange.IncrementRotation intTurn End Sub
二、将文档中的每张图片的版式转换为嵌入式图形
For Each s In Documents("MyDoc.doc").Shapes If s.Type = msoPicture Then s.ConvertToInlineShape End If Next s
三、设置图片的高度宽度
Mywidth=10'10为图片宽度(厘米) Myheigth=10'10为图片高度(厘米) For Each iShape In ActiveDocument.InlineShapes iShape.Height = 28.345 * Myheigth iShape.Width = 28.345 * Mywidth Next iShape
四、得到图片的像素
Sub 获取嵌入型图片的像素() On Error Resume Next With Selection.Range.Find .ClearFormatting .Replacement.ClearFormatting .Execute findtext:="^g", MatchWildcards:=False, Wrap:=wdFindStop MsgBox "该图片的像素为:" & Selection.InlineShapes(1).Width _ & " * " & Selection.InlineShapes(1).Height End With End Sub
五、复制图片到word文档中
Dim objWordApp As Word.Application Dim objWord As Word.Document Range(Cells(3, 2), Cells(11, 11)).Select Selection.CopyPicture Set objWordApp = CreateObject("Word.Application") Set objWord = objWordApp.Documents.Add objWord.Application.Visible = True objWord.Application.Selection.Paste Set objWord = Nothing Set objWordApp = Nothing
|