Results 1 to 12 of 12
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBProject Protection (XP SR3)

    How does one make active a VBProject? I have read Chip Pearson's " "Programming To The VBE"; in particular the section on getting a reference to an object.

    VBProject
    Dim VBProj As VBProject
    Set VBProj = ThisWorkbook.VBProject or in my case ActiveWorkbook.VBProject

    I can successfully protect a project but it is the wrong project (copy of capital requests). For some reason I can not reference the "60056_cap" project.

    If I click on the 60056_cap project itself (left window) and rerun the code, everything works.

    I tried posting the code in this thread but SendKey characters started to mess with the body of text within this thread. I'll capture a screenshot and make another post to this thread.

    John

  2. #2
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Large screenshot cropped by HansV

    Here is a screenshot of the code I previously mentioned

    John

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: VBProject Protection (XP SR3)

    Try this:

    Workbooks("60056_cap.xls").VBProject.VBComponents( "A_DesktopID").CodeModule.CodePane.Window.SetF ocus

    By setting focus to a specific code window in the project, you make it the active VB project.

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Hans,

    I included your suggestion in my code, however the focus is only temporary and does not allow me to perform the SendKey line of code on the correct project.

    As I step through the code I can see the focus being changed to "60056_cap.xls" then immediately jump back to the other project (once the focus line of code is read). One would think if your changing the focus it would stick.

    Regards,
    John

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    But isn't it the debugging that forces the focus back to the project that is being debugged, so when run at run mode the activated project should stay the active project?

    Why are you trying to protect a project by code? It has been written by many that this is an unreliable process, so I guess you're at risk here.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: VBProject Protection (XP SR3)

    As Jan Karel wrote, you shouldn't single step through code like this.

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Jan,

    I have a routine that creates new Excel workbooks based on a template that incorporates some VBA code within each workbook. I'm using the SendKey method to protect the VBProject of each file as I don't want the End Users to be able to access the code.

    I do understand that a XLM file can be generated and then distributed as an Add-in but I am not up-to-date on how to accomplish it.

    Regards,
    John

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Why not include the code in the templates then? Seems a bit awkward to have to add the code to a template.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  9. #9
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Jan,

    I slowly worked my way to that conclusion. One can really get pulled into one concept and not want to let go.

    Thanks,
    John

  10. #10
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Here is a solution to password protect a VPProject via code (written and tested in Excel 2002 SP3):

    Option Explicit

    Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

    Sub ProtectVBProject()
    Dim oWB As Workbook
    Dim strPassword As String

    Set oWB = Workbooks("6004_cap.xls") 'Place your file name here
    strPassword = "Hans"

    oWB.Activate
    With oWB
    With .VBProject.VBE.MainWindow
    .Visible = True
    .SetFocus
    Application.SendKeys "%t": Sleep 50: DoEvents
    Application.SendKeys "e^{TAB}v{TAB}" & strPassword & "{TAB}" & strPassword & "~": Sleep 50: DoEvents
    End With
    .Close True
    End With

    End Sub


    Someone may want to test it in other versions of Excel.

    Many thanks to all who contributed,
    John

  11. #11
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: VBProject Protection (XP SR3)

    I tested it in XL97 and it worked.

    Steve

  12. #12
    Star Lounger
    Join Date
    Apr 2002
    Location
    Vlissingen, Netherlands
    Posts
    63
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: VBProject Protection (XP SR3)

    Works in Excel 2003 SP1 as well.

    Joop

Posting Permissions

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