Consulting

Results 1 to 6 of 6

Thread: Sleeper: Accessing an Excel Module

  1. #1

    Sleeper: Accessing an Excel Module

    What I need to do is run a procedure from one Workbook that will open up another workbook and then open up an existing module for that workbook.

    I have the code to open the workbook and to open the VBE environment window.

    Anyone know how to open up a specific module, and pass the password if it is protected?

    I am looking at some of the following lines of code but cannot get any of them to work in part or in hole.

    Application.VBE.VBProjects.Open
    VBProject.VBComponents("ModuleName").CodeModule
    Thanks,

    Lee

  2. #2
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi Lee,

    Welcome to the forum.

    For a good primer on this topic have a look at Chip Pearson's site.

    Note, however, that there is no built-in way to lock and unlock VBAProjects, even if you do have the password. There simply aren't the required methods/properties. (There is a workaround using SendKeys - but this is not a 100% reliable method and most (all?) professionals would avoid its use.)

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by Richie(UK)
    .. and most (all?) professionals would avoid its use.)
    Rather unfortunately, this isn't always the case; as sad as it is. A related example of setting a VBA project password can be found here.

    Richie, on an unrelated topic (while I have you here ) you posted some syntax one time on this site for opening a workbook with only one sheet (a template type/name). I can't find it anymore and forgot to save it for myself. I can also neither find it in any help files or in any other forum. Do you remember what I'm talking about?

  4. #4
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi Zack,

    Well, there will always be creative people who try to work around the limitations that face them. Sometimes what the create may be useful to others, sometimes not.

    I see I missed an interesting thread there (some people get a little tetchy don't they?).

    I think the code that you refer to was something like this:

    Sub Test()
        Dim wbk As Workbook
    Set wbk = Workbooks.Add(xlWBATWorksheet)
        MsgBox "New book sheet count = " & wbk.Worksheets.Count
    End Sub
    You can find it in the Help files if you dig - look up the Add method and then select the Workbooks object for 'Applies to'. You will see that a number of template constants can be given as an argument. If you don't specify a template you get a 'normal' workbook with the number of sheets determined by the users preferences.

    Its tricky searching forums when you can't quite remember what it is that you are actually trying to find - been there, done that. Nearly as bad as those old text-based adventure games on the good old C64 :

    Enter the Green room (The door is closed.)
    Open the door (I don't understand!).
    Open the Green door (The Green door is locked.)
    Unlock the Green door (You can't unlock the Green door.)
    Unlock the Green door with the Green key (You have unlocked the Green door.)
    Enter the Green room (The door is closed.)
    Open the Green door (You have opened the Green door.)
    Enter the Green room (The Green ogre has killed you. The End!)

    Aaaaaarrrrggghhhhh!!!!!!!!!!!!!!! (Richie has smashed the computer. The End!)

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    ROFLMAO!!!

    Thanks Richie!

    [/hijack]

  6. #6
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Richie(UK)
    ....I see I missed an interesting thread there (some people get a little tetchy don't they?).....
    ROFLMFAO They do indeed, I missed that one too, or I wooda put my 2p in as well...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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