ปรับคุณสมบัติของรูปภาพด้วย AddPicture Method word vba

ฉันต้องแก้ไขคุณสมบัติของรูปภาพที่แทรกโดยวิธี AddPicture

1) ฉันต้องปรับความสูงเป็น 0.5" และความกว้างเป็นตัวแปร (ล็อคอัตราส่วนภาพ)

2) ตัดข้อความ = "อยู่ด้านหน้าข้อความ"

เป็นไปได้ด้วยวิธีนี้หรือไม่? ถ้าเป็นเช่นนั้น ฉันจะเพิ่มคุณสมบัติเหล่านั้นได้อย่างไร? ถ้าไม่ฉันควรใช้วิธีอื่นใดและอย่างไร?

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

person user1783736    schedule 12.12.2013    source แหล่งที่มา
comment
คุณได้ลองใช้ Macrorecorder แล้วหรือยัง?   -  person Kazimierz Jawor    schedule 13.12.2013
comment
ใช่. ไม่ตอบสนองต่อการเปลี่ยนแปลงความสูง และไม่อนุญาตให้มีการเปลี่ยนแปลงการตัดข้อความ   -  person user1783736    schedule 13.12.2013


คำตอบ (1)


ฉันจะทำสิ่งที่คุณต้องการในขั้นตอนต่อไปนี้:

  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
    
person Kazimierz Jawor    schedule 12.12.2013
comment
ขอบคุณมาก. ฉันพยายามคิดเรื่องนี้มานานแล้ว ขอบคุณมาก - person user1783736; 13.12.2013
comment
มีแนวคิดเกี่ยวกับวิธีปรับ/ย้ายรูปภาพไปยังตำแหน่งเฉพาะ (ซ้าย, ขวา) บ้างไหม - person user1783736; 13.12.2013
comment
คุณควรจะสามารถทำงานกับ SHP.Left = x และ SHP.Top = y ได้ ลองอะไรแบบนี้... - person Kazimierz Jawor; 14.12.2013