Reputation: 337
So for my particular application, I want to be able to select an image after I've copied it in from Excel, and then insert a caption.
I can successfully copy images using:
docapp.Selection.Range.PasteSpecial DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine
However, I'm having a lot of difficult just selecting the recently copied image so I can use
Selection.InsertCaption
What's the best way to select images?
Upvotes: 2
Views: 5654
Reputation: 337
Ok, I'm an idiot and have solved my own problem. It's not the prettiest code but it works:
The key is to use 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
Upvotes: 4