Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Excel - Drag & Drop Hyperlinker


  • Please log in to reply
8 replies to this topic
Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011
This script allows you to drag and drop files of any document format into Excel worksheets, thereby creating automatic hyperlinks.



Hover over a file on your desktop or folder. A tooltip will appear showing the icon for the file type and the path of the file.
Posted Image


Drag it into an open Excel file
Posted Image


Drop it and a hyperlink will be created in the active cell
Posted Image


Notes:
-used HotKeyIt's ToolTip Library.
-the icon's for the tooltips are .png files with transparency.


Instructions:
1) Press "\\" to run the script
2) Hover over a file on your desktop or folder and hold down the Shift key.
3) Drag the cursor to an Excel worksheet and release the Shift key.
4) A hyperlink to the file will be created.
**After each drop.. make sure to reload the script with "\\" so the shift key doesn't conflict with other scripts

Download:
Excel - Drag & Drop Hyperlinker


YouTube:
GRpbcJEdPBQ


-Used "\\" to run after each time
-Hold Shift key to drag to Excel
#SingleInstance Force

:*:\\::

;########## Copy file path ###########
Loop
{
GetKeyState, state, Shift
	if (state = "D")
	{
		clipboard =
		SendInput, ^c
		ClipWait
		Clipboard := Clipboard
		break
	}
Sleep, 50
}
;#######################################

gosub, Label_show_TT

;########## Paste hyperlink to path in Excel ###########
Loop
{
GetKeyState, state, Shift
	if (state = "U")
	{
		Click
		Sleep, 100
		Click 2
		SendInput, ^k
		WinWaitActive Insert Hyperlink
		SendInput, ^v
		Send, {enter}
		break
	}
Sleep, 50
}
;#######################################

gosub, Label_Remove

return


;http://www.autohotkey.com/community/viewtopic.php?p=404058#p404058


;######### Label_show_TT ###############
Label_show_TT:
SplitPath, Clipboard,,,ext, ;get extension of file on Clipboard

TT:=TT(),TT.Show(Clipboard,"","","Link to:", find_icon(ext),"")  ;create ToolTip
Loop
{
	GetKeyState, state, Shift
		if (state = "D")
		{
			TT.Show() ;show ToolTip at mouse coordinates
			Sleep, 10
		}
		else
		{
			TT_Remove()
			break
		}
}
return
;#######################################


Label_Remove:
TT_Remove()
return


;######### find_icon ###############
find_icon(ext)
{
	SetWorkingDir, %A_ScriptDir%\Icons
	;MsgBox, %A_WorkingDir%\xltrans.png
	
	if (ext = "xlsx" or ext = "xls" or ext = "xlsm")
		icon_file = %A_WorkingDir%\Excel.png
	else if (ext = "docx" or ext = "doc")
		icon_file = %A_WorkingDir%\Word.png
	else if (ext = "pdf")
		icon_file = %A_WorkingDir%\PDF.png
	else if (ext = "ahk")
		icon_file = %A_WorkingDir%\AHK.png
	else if (ext = "")
		icon_file = %A_WorkingDir%\Folder.png
	else
		icon_file = %A_WorkingDir%\Other.png
	
	return icon_file
}
;#######################################

Ideas and improvements welcome!

radjoe
  • Members
  • 1 posts
  • Last active: Sep 20 2012 03:30 PM
  • Joined: 20 Sep 2012
Link is dead

  • Guests
  • Last active:
  • Joined: --
Does anyone have a link to this file ?

Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011
updated link, thx

Quest
  • Guests
  • Last active:
  • Joined: --
Is there an easy way to drag an existing URL "OUT OF" an Excel spreadsheet and into a text file to extract that URL?

Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011

Is there an easy way to drag an existing URL "OUT OF" an Excel spreadsheet and into a text file to extract that URL?

Is this what you are looking for?

Hover over any cell in Excel and hold the right mouse button down for more than 0.5 seconds. The contents will be copied to the clipboard and pasted when you release the right mouse button.

Download:
Excel Drag URL

YouTube:
EWb8Lkb98m0




#SingleInstance Force
#IfWinActive ahk_class XLMAIN


RButton::
XL := Excel_Get()

now_1 := A_TickCount  ;initial time

loop,
{
  now_2 := A_TickCount  ;current time
  elapsed_time := now_2 - now_1  ;elapsed time since Rbutton held down
  
  GetKeyState, state, Rbutton, P
  if (state = "U" and elapsed_time < 500)
  {
	 Click Right ;retain native function if released under 500 ms
	 break
  }
  else if (state = "D" and elapsed_time > 500)
  {
	 gosub Label1 ;if held down longer than 500 ms... open link in new tab
	 break
  }
}

return


Label1:

Send, {Click, Right}{esc}
Clipboard := XL.ActiveCell.Value

gosub, Label_show_TT


;########## Paste hyperlink to path in Excel ###########
Loop
{
GetKeyState, state, Rbutton, P
	if (state = "U")
	{
		Send, {click}
		SendInput, ^v
		break
	}
Sleep, 50
}
;#######################################
 
gosub, Label_Remove
return


;http://www.autohotkey.com/community/viewtopic.php?p=404058#p404058

;######### Label_show_TT ###############
Label_show_TT:
;SplitPath, Clipboard,,,ext, ;get extension of file on Clipboard

ext := "other"  ;Use windows icon for URLs

TT:=TT(),TT.Show(Clipboard,"","","Link to:", find_icon(ext),"")  ;create ToolTip
Loop
{
	GetKeyState, state, RButton, P
		if (state = "D")
		{
			TT.Show() ;show ToolTip at mouse coordinates
			Sleep, 10
		}
		else
		{
			TT_Remove()
			break
		}
}
return
;#######################################


Label_Remove:
TT_Remove()
return


;######### find_icon ###############
find_icon(ext)
{
	SetWorkingDir, %A_ScriptDir%\Icons
	
	if (ext = "xlsx" or ext = "xls" or ext = "xlsm")
		icon_file = %A_WorkingDir%\Excel.png
	else if (ext = "docx" or ext = "doc")
		icon_file = %A_WorkingDir%\Word.png
	else if (ext = "pdf")
		icon_file = %A_WorkingDir%\PDF.png
	else if (ext = "ahk")
		icon_file = %A_WorkingDir%\AHK.png
	else if (ext = "")
		icon_file = %A_WorkingDir%\Folder.png
	else
		icon_file = %A_WorkingDir%\Other.png
	
	return icon_file
}
;#######################################


knsheffield
  • Members
  • 1 posts
  • Last active: Nov 04 2012 02:29 AM
  • Joined: 04 Nov 2012
Hello! Great functionality! But I get this error when I try to run the script.

Error at Line 2.
Line Test: #Include <My_Func>
Error: Function library not found.
The program will exit.

I'm a newbie at this so any advise will help...in layman's terms. :)

thanks!

douggpybus
  • Members
  • 1 posts
  • Last active: Feb 04 2013 04:55 PM
  • Joined: 02 Feb 2013

Hi

I am trying to run this script but I get an error message, this is all new to me and I am probably be doing something wrong.

I have copied the script into AHK editor and saved it. I tried double clicking the icon to run the script but I get the following error message, also how do you use the collowing ketstroks "\\"

I would be grateful for any help.

 

 

Error: Call to nonexistent function


 

Specfically: TT(),TT.Show(Clipboard.”,”,”Link to:”,find_icon(exit),”)

Line#

040:Break

041:}

042:Sleep,60

043:}

046: GoSub,Label_Remove

048: Return

056: Splitpath,clipboard,,,ext

058: TT:=TT(),TT.Show(Clipboard,””,””,”Link to:”,find_icon(ext),””)

059: Loop

060: {

061: GetkeyState,state,shift

062: if(state=”D”

063:{

064: TT.Show()

065: Sleep,10


 

The Program will exit.

 

Regards, Doug

.



knightslacker
  • Members
  • 1 posts
  • Last active: Sep 16 2013 05:17 AM
  • Joined: 16 Sep 2013

i cannot download, please reload the file...