Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2016, 08:00 AM
Izzie7 Izzie7 is offline Format figure pasted from browser Windows 7 64bit Format figure pasted from browser Office 2010 32bit
Novice
Format figure pasted from browser
 
Join Date: Nov 2014
Location: Israel
Posts: 5
Izzie7 is on a distinguished road
Default Format figure pasted from browser

After pasting a figure from browser, I want to remove the hyperlink and resize the shape. I tried recording the steps but the resize did not recored and what did record was this:
Sub Macro1()


'
' Macro1 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.ShapeRange.Hyperlink.Delete
End Sub

When run, the hyperlink was removed, but then the macro stopped with an error message.
How can this simple task be done with VBA?
I thank you in advance!
Reply With Quote
  #2  
Old 05-19-2016, 09:15 PM
gmayor's Avatar
gmayor gmayor is offline Format figure pasted from browser Windows 10 Format figure pasted from browser Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you copy an image from the browser the hyperlink doesn't normally come with it, so the error relates to there not being a hyperlink to delete. You can error trap that

Code:
Sub Macro1()
Dim oRng As Range
Dim oLink As Hyperlink
Dim oShape As InlineShape
    Set oRng = Selection.Range
    oRng.Paste
    For Each oLink In oRng.Hyperlinks 'If there is one
        oLink.Delete
    Next oLink
    For Each oShape In oRng.InlineShapes
        With oShape
            .Width = InchesToPoints(3) 'The width sets the size of the image with the same aspect ratio
        End With
    Next oShape
lbl_Exit:
    Set oRng = Nothing
    Set oLink = Nothing
    Set oShape = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-29-2016, 04:02 AM
Izzie7 Izzie7 is offline Format figure pasted from browser Windows 7 64bit Format figure pasted from browser Office 2010 32bit
Novice
Format figure pasted from browser
 
Join Date: Nov 2014
Location: Israel
Posts: 5
Izzie7 is on a distinguished road
Default

Thanks!
It works great. I also added a picture border.
Just one question: What is the purpose of the lbl_Exit label? to use with On Error GoTo?
Reply With Quote
  #4  
Old 05-29-2016, 04:34 AM
gmayor's Avatar
gmayor gmayor is offline Format figure pasted from browser Windows 10 Format figure pasted from browser Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The label has no specific use in this code sequence. It's a programming style that I developed from sharing macro development with my friend and colleague Greg Maxey. I use it in all my macros, but, as you suggest, it can be used an aid to error trapping or code ending.
If error trapping I might add a label err_Handler: after Exit sub to process the error then return to lbl_Exit to clean up and end.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
hyperlinks, resize objects, shapes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Caption Order: Figure 4 Figure 3 Figure 2 golfarchitect13 Word 5 05-07-2014 07:15 PM
Footnotes do not appear when document is pasted into new format JerryL Word 4 12-09-2013 04:33 PM
Format figure pasted from browser Figure and Table Numbering Format Change hojkoff Word 3 06-18-2013 01:57 AM
Format figure pasted from browser auto-format items pasted into document ekphrasis Word 1 11-01-2010 03:02 PM
hyperlinks from copying in web browser are long format... BERKEY Word 0 12-14-2007 10:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft