Macro Hyperlink

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I need to attach each cell in a column an hyperlink that would be the google search address of the cell content.

Is is possible ?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
paste the NativeApp code (bottom) into a module.
This will open any document in its native application. ###.docx will open in word, ##.xlsx will open in excel

for web google usage:

Code:
vSite = "https://www.google.com/search?q=" & txtBox
OpenNativeApp vSite


-----paste this into a module

Code:
Option Compare Database
Option Explicit

#If VBA7 Then
  'Declare PtrSafe Sub...
    Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
#Else
   'Private Declare ptrsafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
   'Private Declare ptrsafe Function GetDesktopWindow Lib "user32" () As Long
#End If

Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, Msg As String

r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            Msg = "File not found"
        Case SE_ERR_PNF
            Msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            Msg = "Access denied"
        Case SE_ERR_OOM
            Msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            Msg = "DLL not found"
        Case SE_ERR_SHARE
            Msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            Msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            Msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            Msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            Msg = "DDE busy"
        Case SE_ERR_NOASSOC
            Msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            Msg = "Invalid EXE file or error in EXE image"
        Case Else
            Msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub

Private Function StartDoc(psDocName As String) As Long
Dim Scr_hDC As Long

Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
End Function
 
Upvote 0
Hi and thank you for the solution!
I need some help how to do this , I paste the NativeApp code into a module then how do I use the code on a specific column in sheet with many populated columns ?
 
Upvote 0
In other words I don't know or understand very well how am I supposed to make this work:
vSite = "Google" & txtBox
OpenNativeApp vSite

also when I place the whole code above in a macro my other macros dont work
 
Upvote 0

Forum statistics

Threads
1,214,549
Messages
6,120,149
Members
448,948
Latest member
spamiki

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