How to recall a path from clipboard for a macro to use

makhtoot

New Member
Joined
Aug 7, 2011
Messages
18
Hello Dear Friends
I have a very simple Macro Code but want to alter a part of it. i want instead of the line in front of the Address, paste the path from the clipboard. the code is like this:


Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+d
'
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="D:\Test\0157.jpg"
End Sub


Thank you in advance
smile.gif
 
Here is a variation of PGC's code but without the need to set a reference to the MS Forms2.0 library at design time - See if it now works for you.

Code:
Sub test()

    Dim DObj As Object
    Dim s As String
    
    Set DObj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    ' Get the text in the clipboard into s
    DObj.GetFromClipboard
    s = DObj.GetText
    Set DObj = Nothing
    ' add the hyperlink
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=s

End Sub
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi Jaafar

Nice! Did not know how to do it without setting the reference.


Hi makhtoot

I thought that your problem was to know how to get the text in the clipboard, which you now know how to do (in 2 ways). It seems, though, that there's something else you need?
 
Upvote 0
thank you my friends
it did exactly what i asked for but. but one other question, how can i assign a shortcut key to this one?
thank you again for all the kind help
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top