Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2004, 09:04 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hide VBA code when forwarding macro

Hi all,

I am writing macros on report for entire team and then forward them for the others to use by doing an export of the macro and forwarding the .bas file. This implies however, that everyone can also see/change the code behind it. Is there a way in forwarding macros and hide your code?

Thx to let me know and rgds,
Sylvie

 
Old August 16th, 2004, 02:37 AM
Authorized User
 
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The usual method is to keep the code within a workbook, when it can be password protected in VB Editor via Tools/VBA Project-Project properties.


-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
 
Old August 18th, 2004, 08:04 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,

I already tried this and now it just asks me to enter my password when i want to edit the project, but when forwarding it it just shows code and doesn't ask others for the password.
Am I doing something wrong? Anyone else has an idea?

Thx in advance and grtz,
Sylvie


 
Old August 24th, 2004, 08:36 AM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,

Are you forwarding the Workbook or the .Bas file to these colleagues?

Regards

John

 
Old August 25th, 2004, 12:59 PM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am forwarding the bas files as the macro needs to be run on different workbooks every week.

 
Old August 26th, 2004, 05:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about forwarding your code as an AddIn (.xla)?
 
Old September 2nd, 2004, 05:22 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, but I didn't work with add-in's yet. Could you pls explain how I can save my macro as an add-in?

Thx a lot in advance,
Sylvie

 
Old September 2nd, 2004, 10:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it would be simpler if I try to show you an example.

I want to multiply any number in cells(1,1) with 33.

In a module, write the following code:

Sub test_addIn()
Dim x, y As Integer
x = Cells(1, 1).Value
y = x * 33
Cells(1, 1).Value = y
End Sub

To be able to start execution, you'll have to make a menu. Add this to the module:

Sub AddNewMenu()
Dim HelpMenu As CommandBarControl
Dim MenuItem As CommandBarControl
Dim SubMenuItem As CommandBarButton
Dim NewMenu As CommandBarPopup

Set HelpMenu = CommandBars(1).FindControl(ID:=30010)
    If HelpMenu Is Nothing Then
        Set NewMenu = CommandBars(1).Controls.Add(Type:=msoControlPopup, temporary:=True)
    Else

        Set NewMenu = CommandBars(1).Controls.Add(Type:=msoControlPopup, before:=HelpMenu.Index, temporary:=True)
    End If
NewMenu.Caption = "T&est"

Set MenuItem = NewMenu.Controls.Add(Type:=msoControlButton)
    With MenuItem
        .Caption = "XLA-test"
        .FaceId = 162
        .OnAction = "test_addIn"
    End With

End Sub

As you only want the user to see your menuitem when using the xla, add also this:

Sub DeleteNewMenu()
    On Error Resume Next
    CommandBars(1).Controls("Test").Delete
End Sub

In ThisWorkbook, add the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
    DeleteNewMenu
End Sub

Private Sub Workbook_Open()
    AddNewMenu
End Sub

Now go back to your empty excel workbook, click X to close the workbook and say Yes to save it first. Choose to save it as an .xla file and give it a proper name. Maybe Office will change to the AddIn directory by itself before saving it. Otherwise you can do it yourself.

Save it and close Excel.

Open Excel and open a new workbook. You won't see the menuitem Test yet. Go to the menu Functions. In the bottom last section there should be an item where you can activate addins. Not sure about the english name but if you have saved the .xla in the AddIn library as described before, you should be able to find the name in the list. Mark the item. Now the menuitem Test should appear in your menu.

Write 123 in cells(1,1) and open the menu Test and click XLA-test. Now the value should be multiplied with 33.

In your case, it might be worth knowing that you can activate the .xla from any position just by opening it in Excel. When you do that, the only thing you'd notice is the new menuitem Test, no workbook appear. However, your macrocode is available from the menu.

To protect your code, open VBEditor, rightclick the .xla projectname and choose Project Properties. Under protection you can write a password which will be necessary to see the code.

This was a lot of words. Hope you can make it work bu if not let me know.

This address gives a more in depth description of creating AddIns. Also have a look at the 'Using Add-In Functions in Your VBA Code'.

http://www.fontstuff.com/vba/vbatut03.htm





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell computation using vba/Macro zone Excel VBA 6 August 2nd, 2007 10:38 AM
macro help for the VBA impaired Christen Beginning VB 6 2 July 17th, 2006 02:09 PM
How to hide VBA code james gold Excel VBA 12 November 14th, 2005 10:59 AM
Hide table with VBA mmcdonal Access VBA 5 June 24th, 2005 10:13 AM
Hide Row with VBA Butch Excel VBA 2 November 24th, 2004 09:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.