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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi

Try the following:

- in the VBEditor in Tools->References, set the reference to

Microsoft Forms 2.0 Object Library

- Try:

Code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+d
'
Dim DObj As DataObject
Dim s As String
 
' Get the text in the clipboard into s
Set DObj = New DataObject
DObj.GetFromClipboard
s = DObj.GetText
Set DObj = Nothing
 
' add the hyperlink
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=s
End Sub
 
Upvote 0
Thanks for your Help, But it turned out that the code copies the upper cell of the current cell that i run the macro on with the same name and hyperlink. any suggestion? thank you very much anyway
 
Upvote 0
Thanks for your Help, But it turned out that the code copies the upper cell of the current cell that i run the macro on with the same name and hyperlink. any suggestion? thank you very much anyway

Sorry, this makes no sense to me.

Please do the following test.

- select some text and press CTRL-C to copy the text into the clipboard

- execute the code below.
You should see a message box with the text in the clipboard.

Please test.


Code:
Sub Test()
Dim DObj As DataObject
Dim s As String
 
' Get the text in the clipboard into s
Set DObj = New DataObject
DObj.GetFromClipboard
s = DObj.GetText
Set DObj = Nothing
 
' display the text from the clipboard
MsgBox s
End Sub
 
Upvote 0
Hello and thank you for your help
i assume that i should run this code in VB console, but when i run it it gives me a compile error and highlights the first line of the code for me???
 
Upvote 0
Hello and thank you for your help
i assume that i should run this code in VB console, but when i run it it gives me a compile error and highlights the first line of the code for me???

Did you set the reference, as I wrote in my post?



Also a remark:

If you get an error when running code always post somthing like:

It highlighted this line

' copy the line here '

and displayed this error message

' the text of the error message here '
 
Upvote 0
Hello Dear Friend
Here is the error in the form you showed me to post:

Code:
It highlighted this line in blue while error window opens:
 
[B]DObj As DataObject[/B]
 
when i click ok on error window, it highlights this line in yellow:

[B]Sub Test()[/B]

and here is the error message:

[B]Compile Error
User-Defind type not defined[/B]
Thanks in advance:)
 
Last edited:
Upvote 0
Ah, much easier.

Your problem seem to be exactly what I've diagnosed before. I'm almost sure you did not set the reference to the library!!

Please refer to my first post in this thread to set the reference to the MsForms library and then try running this last code I posted again.
 
Upvote 0
Hello dear friend
Thank you for the heads up, i activated the library the first time you told me to, but since it wasn't found in the library list, i had to select it manually from the system32 folder so it could load it in the excel 2007. i think that's why it was not activated and i had to load it again. it worked and it gave me a list of all the files i copied into clipboard. what next?:)
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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