2014-11-05 79 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