Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 9th, 2004, 09:04 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old August 16th, 2004, 02:37 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
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.
Reply With Quote
  #3 (permalink)  
Old August 18th, 2004, 08:04 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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


Reply With Quote
  #4 (permalink)  
Old August 24th, 2004, 08:36 AM
Registered User
 
Join Date: Aug 2004
Location: Birkenhead, Wirral, United Kingdom.
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

Reply With Quote
  #5 (permalink)  
Old August 25th, 2004, 12:59 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
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.

Reply With Quote
  #6 (permalink)  
Old August 26th, 2004, 05:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about forwarding your code as an AddIn (.xla)?
Reply With Quote
  #7 (permalink)  
Old September 2nd, 2004, 05:22 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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

Reply With Quote
  #8 (permalink)  
Old September 2nd, 2004, 10:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.