Declare Global Variable and use in Worksheet Sub?

NewYears1978

Board Regular
Joined
Feb 25, 2014
Messages
107
Hey all. I have a macro that asks the user which browser they prefer, then sets that location in a variable. Then in a worksheet I have a follow hyperlink macro that uses that variable however the variable information is not being passed.

The info is being stored properly because the msgbox at the end of the inputbox macro shows correct. What am I missing?
The global car is called AppLoc

My main macro is in a module:

Code:
Option Explicit
Global AppLoc As String

Public Function ChooseBrowser() As String
 Dim s As String
 
 s = InputBox("Please type in your number of your preferred browser:" & vbCrLf & _
         vbCrLf & vbTab & "1 for Chrome" & _
         vbCrLf & vbTab & "2 for Firefox" & _
         vbCrLf & vbTab & "3 for Edge", "Option Chooser")
 
 Select Case s
     Case "1"
       If Dir("C:\Program Files\Google\Chrome\Application", vbDirectory) <> "" Then '64 bit paths
           AppLoc = "C:\Program Files\Google\Chrome\Application\chrome.exe"
    
        Else '32 bit paths (some 32 and 64 are the same)
            AppLoc = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
        End If
   
     Case "2"
        If Dir("C:\Program Files\Google\Chrome\Application", vbDirectory) <> "" Then '64 bit paths
           AppLoc = "C:\Program Files\Mozilla Firefox\firefox.exe"
               
        Else '32 bit paths (some 32 and 64 are the same)
           AppLoc = "C:\Program Files\Mozilla Firefox\firefox.exe"
        End If
    
     Case "3"
        If Dir("C:\Program Files\Google\Chrome\Application", vbDirectory) <> "" Then '64 bit paths
            AppLoc = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
    
        Else '32 bit paths (some 32 and 64 are the same)
            AppLoc = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
       
        End If
     Case Else
    
 End Select
 
 MsgBox AppLoc
 
End Function

Then on a worksheet I have this
Code:
Option Explicit

Private Sub Worksheet_FollowHyperlink(ByVal objLink As Hyperlink)
    Application.EnableEvents = False
    Dim strAddress As String
        
        MsgBox AppLoc
        
    If ActiveCell.Column = 21 Then
        strAddress = "https://www.1000bulbs.com/customer/sales_edit/" & objLink.Parent.Offset(0, -19).Value
    Else
        strAddress = objLink.Parent.Offset(0, -1).Value
    End If
    
    Dim dblReturn As Double
    dblReturn = Shell(AppLoc & " " & strAddress, 1)
    Application.EnableEvents = True
End Sub


Nothing is being displayed for AppLoc and the macro isn't working. Some how the variable is not being passed...what am I doing wrong? Thanks in advance :)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I think I fixed it, I had to make a new variable in the Worksheet sub AppLoc2 then have AppLoc2 = AppLoc - that seemed to work - is that the right solution or is there a cleaner one?
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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