Mike De Salvo
Board Regular
- Joined
- Jul 11, 2012
- Messages
- 80
Looking for a macro to replace a picture with an image copied to the clipboard. I found the following that works in Word.doc; but I need one that will work Excel. Any ideas?
Code:
[COLOR=#333333][FONT=Segoe UI]Sub ReplacePictureWithClipboarPicture()[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]Dim oILS As InlineShape[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]Dim LngW As Long[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]If Selection.Type = wdSelectionInlineShape Then[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] Set oILS = Selection.InlineShapes(1)[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] LngW = oILS.Width[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] oILS.Delete[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] Selection.Range.Paste[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] If Selection.Type = wdSelectionInlineShape Then[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] Set oILS = Selection.InlineShapes(1)[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] With oILS[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] .LockAspectRatio = True[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] .Width = LngW[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] End With[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] Else[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] ActiveDocument.Undo (3)[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] MsgBox "Operation canceled and reversed. The content of the clipboard was not a inline shape image."[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] End If[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]Else[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI] MsgBox "Please select the image to replace and try again. The image must be an inline shape image."[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]End If[/FONT][/COLOR]
[COLOR=#333333][FONT=Segoe UI]End Sub[/FONT][/COLOR]