Hyperlink to Modules

Nalani

Well-known Member
Joined
Apr 10, 2009
Messages
1,047
Is it possible to Hyperlink to a Module?

I have a list of all my Modules.
Module1, Module2, etc. (of course with meaningful names)

What I'm looking for is if there is a way to click on Module1 from the List, it will open that module in the VBE for whatever I want to do with it, read, modify, etc.

I've done some searching but only found a way to Run it. Don't want to Run, just Open for Viewing/Modification.
 
Nalani, DK,

1. Again, I still cannot reproduce the fact that Excel is in edit mode, and we need to select another cell first. For me and my (standard) installation of Excel, it is NOT.

2. About "Trust Access to VBA Project": that is what mentioned on Chip's page, so that should be set correctly prior to using the macro. Simply conveying the message to the user(s) that this is a prerequisite to use the code in a good way.

Hi Wigi

Regarding point 1, what happens if you double-click a cell normally (i.e. without any VBA code running)? For me (and also the OP it appears) double-clicking in the cell is the same as pressing F2 in the cell (edit mode). Setting the Cancel argument to true prevents this.

DK
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Wigi

Regarding point 1, what happens if you double-click a cell normally (i.e. without any VBA code running)? For me (and also the OP it appears) double-clicking in the cell is the same as pressing F2 in the cell (edit mode). Setting the Cancel argument to true prevents this.

DK

Indeed, then I don't go in Edit mode...
 
Upvote 0
Hi All,

Wigi,

I'm currently in 2000. My guess would be that you have 'Edit Directly in Cell' un-ticked under Tools|Options|(Edit Tab)
 
Upvote 0
Wigi,

I'm currently in 2000. My guess would be that you have 'Edit Directly in Cell' un-ticked under Tools|Options|(Edit Tab)

Hello GTO,

I'm on Excel 2007, but yes you are right regarding that setting.
 
Upvote 0
Thanks GTO - forgot about that setting.

So it would make more sense to use Cancel = True as this allows for the possibility of both settings. If the user has "Enable editing directly in cells" unchecked then the line will have no effect. If it's checked then the line will prevent edit mode being activated.

DK
 
Last edited:
Upvote 0
Thanks GTO - forgot about that setting.

So it would make more sense to use Cancel = True as this allows for the possibility of both settings. If the user has "Enable editing directly in cells" unchecked then the line will have no effect. If it's checked then the line will prevent edit mode being activated.

DK


Yes Sir, and at least AFAIK, utterly true, as the event would never be called.
 
Upvote 0
:oops: Yikes! :oops: and of course you are perfectly correct. One too many adult beverages last night:rolleyes:.
 
Upvote 0
Thanks to all. :)

wigi, your code is 'Nifty" as you stated above.

I took the advice from dk about the use of On Error Resume Next.
Commented out that statement first of all, just to see if there was an Error.
I then limited my Target to Column A.
It did throw an error if I DoubleClick in an empty cell.
Error was on this line:
Code:
 If Len(.VBComponents(sModule).Name) = 0 Then
Subscript out of range

I thought there might be 2 types of errors:
1. What dk mentioned about Access to the VBA Project
2. In case a blank cell was clicked

This is what I came up with. Seems to work right, but not sure if I made the right adjustments.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim ProcKind As VBIDE.vbext_ProcKind
    Dim sModule As String
    Dim bCancelDefault As Boolean
 
    If Target.Column > 1 Then Exit Sub
    On Error GoTo ErrHandler
 
    sModule = Target.Value
 
    'Assume that the default action needs to be cancelled
    bCancelDefault = True
 
    With ActiveWorkbook.VBProject
        If Len(.VBComponents(sModule).Name) = 0 Then .VBComponents.Add(vbext_ct_StdModule).Name = sModule
        With .VBComponents(sModule).CodeModule
            If .CountOfLines > .CountOfDeclarationLines Then
                'there is at least 1 procedure in the module
                Application.Goto .ProcOfLine(.CountOfDeclarationLines + 1, ProcKind)
            Else
                'there are no procedures in the module: make a temporary procedure, jump to it and remove the procedure again
                .InsertLines 1, "Sub TestProc()"
                Application.Goto "TestProc"
                .DeleteLines 1
            End If
        End With
    End With
 
    'If the procedure has opened the VBE then cancel the default action (starts edit mode in the cell)
    Cancel = bCancelDefault
    Exit Sub
 
ErrHandler:
    If Err.Description Like "Programmatic access to Visual Basic Project*" Then
        MsgBox "Please adjust your security settings to allow access to VB project.", vbExclamation, "Error"
 
    Else
        MsgBox "Please choose from the list in Column A", vbExclamation, "Error"
        Cancel = bCancelDefault
    End If
 
End Sub
 
Upvote 0
Sorry, forgot to mention that when the error occured, it would Add a module without any lines of code,

From what I can figure out, this was the intention of wigi's code.

But I didn't need the added module. So my adjustment took care of that.
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,088
Members
452,611
Latest member
bls2024

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