Consulting

Results 1 to 3 of 3

Thread: open specific module

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    open specific module

    hello
    is it possible to open the vb editor exactly at a specific module .
    maybe through a inputbox to which the user will enter the module name or number?
    and get a message if it is not there- "module do not exist,please try again".
    thanks
    moshe

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi lior03,

    I've come up with the code below:
    [VBA]
    Function ModuleExists(ModuleName As String) As Boolean
    On Error Resume Next
    ModuleExists = Len(ThisWorkbook.VBProject.VBComponents(ModuleName).Name) <> 0
    End Function

    Sub OpenModule()
    'Searches for module (held in strModule) and displays it if found.
    'Uses Function ModuleExists

    Dim strModuleName As String
    strModuleName = "Module1" 'The name of the module to find

    If ModuleExists(strModuleName) Then
    MsgBox strModuleName & " found."
    Application.VBE.MainWindow.Visible = True 'Show the VBE
    'Display the found module:
    ThisWorkbook.VBProject.VBComponents(strModuleName).Activate
    Else
    MsgBox strModuleName & " module do not exist,please try again"
    End If

    End Sub
    [/VBA]

    Change the contents of strModuleName in Sub OpenModule
    to the name of the module you want to search for.

    Hope this helps...

    Marcster.

  3. #3
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    How about this ?

    [VBA]
    Sub FindModule()
    Dim VBComp As VBIDE.VBComponent
    Dim Module As String
    On Error Resume Next
    Module = InputBox("What module do you wish to open?")
    Application.ActiveWorkbook.VBProject.VBComponents.Import ("C:\" & Module & ".bas")
    If Err = "53" Then
    MsgBox "Module do not exist,please try again."
    End If

    End Sub
    [/VBA]


    The code wont work until you install your VBA reference. Go to tools in your VBA screen and click on References and look for:

    Microsoft Visual Basic for Applications Extenssiblity 5.3

    Then check mark it.

    Then go to your regular excel screen and go to Tools- Macro -Security- trusted publishers and check mark in the box that says:

    Trust access to Visual Basic Prodject.
    Last edited by Shazam; 12-28-2005 at 10:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •