2014-11-05 23 views
1

因此,對於我的特定應用程序,我希望能夠從Excel中複製後選擇圖像,然後插入標題。vba詞:如何選擇圖像?

我可以用成功複製圖片:

docapp.Selection.Range.PasteSpecial DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine 

不過,我有很多困難只是選擇最近複製的圖像,這樣我就可以使用

Selection.InsertCaption 

什麼是最好的方式選擇圖像?

回答

3

好吧,我是個白癡,已經解決了我自己的問題。這不是最漂亮的代碼,但它的工作原理:

的關鍵是使用document.InlineShapes.Select

Public Sub Chart2Word(chto As Chart, doc1 As Word.Document, docapp As Word.Application, _ 
        Optional Title As Variant) 
    Dim objpic As Word.InlineShape 


    docapp.Activate 
    chto.CopyPicture 

    docapp.Selection.MoveEnd wdStory 
    docapp.Selection.Move 
    docapp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 

    docapp.Selection.Range.PasteSpecial DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine 

    doc1.InlineShapes(doc1.InlineShapes.Count).Select 
    Label = Me.Range("LabelName").value 
    If Not IsMissing(Title) Then 

     docapp.Selection.InsertCaption Label:=Label, Title:=": " + Title 
    End If 
+0

+2的嘗試,-1太早到達求救= d – Alex 2014-11-05 17:26:32