Dzwebs.Net

撰写电脑技术杂文十余年

vba设置word图片格式

Admin | 2011-6-20 8:33:48 | 被阅次数 | 11326

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  以下内容,是通过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


该杂文来自: Word杂文

上一篇:图片排版的出血概念

下一篇:word排版红头文件、公文的技巧

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计