萬盛學電腦網

 萬盛學電腦網 >> WORD教程 >> WORD使用技巧 >> vba設置word圖片格式

vba設置word圖片格式

  一、旋轉圖片

  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

copyright © 萬盛學電腦網 all rights reserved