2013-12-12 33 views
1

我需要编辑由AddPicture方法插入的图像的属性。使用AddPicture方法调整图像属性方法字vba

1)我需要的高度调整到0.5" ,宽度是可变的(锁定的宽高比)。

2)环绕文本=‘以文字上方’

这是possile与这种方法如果让我怎么添加这些属性如果没有,我应该用什么样的方法,以及如何

Sub replaceWithImage() 

Dim imageFullPath As String 
Dim FindText As String 
imageFullPath = "C:\Logo.jpg" 
FindText = "PlaceHolder" 

'Application.ScreenUpdating = False 
With Selection 
    .HomeKey Unit:=wdStory 

    With .Find 
     .ClearFormatting 
     .text = FindText 
     ' Loop until Word can no longer 
     ' find the search string, inserting the specified image at each location 
     Do While .Execute 
      Selection.MoveRight 
      Selection.InlineShapes.AddPicture FileName:=imageFullPath, LinkToFile:=False, SaveWithDocument:=True 
     Loop 

    End With 
End With 


    End Sub 
+0

你试图与宏记录? –

+0

是的。不对高度变化做出响应,并且不允许更改包装文字 – user1783736

回答

4

我会做什么,你需要按以下步骤:???

  1. ,而不是这一行:

    Selection.InlineShapes.AddPicture FileName:=imageFullPath, _ 
              LinkToFile:=False, SaveWithDocument:=True 
    
  2. 我会做同样的,但使用Object Variable

    'a) create new shape as object variable 
    Dim SHP 'As InlineShape/As Shape 
    Set SHP = Selection.InlineShapes.AddPicture(FileName:=imageFullPath, _ 
              LinkToFile:=False, _ 
              SaveWithDocument:=True) 
    'b) changes made according to SHP varialbe: 
    With SHP 
        'this will convert to 'in front of text' 
        .ConvertToShape 
        'this will keep ratio 
        .LockAspectRatio = msoTrue 
        'this will adjust width to 0.5 inch 
        .Width = InchesToPoints(0.5) 
    End With 
    
+0

非常感谢。我一直试图弄清楚这一点很长一段时间。非常感谢 – user1783736

+0

关于如何调整/移动图像到特定位置(左,右)的任何想法? – user1783736

+0

您应该可以使用'SHP.Left = x'和'SHP.Top = y'。尝试像这样... –