sydney2000


Hi,

I am currently working on an Excel Workbook where I have added a brand new code module called "Calculations2007".

This module (*.bas) file contains several new functions. I have been searching on the web on how to deploy this

new module in my workbook to a group of production workbooks. Basically I need this new code to get to production.

I have gotten to a point where I know how to write the functions out. But it always creates a module called "Module1"

and with my functions in it. How do I tell it to create these new functions (or macros) to a module called

"Calculations2007" By the way, I am doing this in VB.NET.

Thanks for your help!

-Sydney




Re: *** How can I add module code to a specific module? *** NEED HELP !!!!

Shasur


The following could get you near that:

Insert Procedure to a Module Using VBComponents

Insert Procedure to a Module Using VBComponents

Code Block
Sub Insert_PRocedure_To_BasModule()

' This program will need reference to Microsoft http://amazon.com/gp/product/0735621314 ie=UTF8&tag=vtt-20&link_code=em1&camp=212341&creative=384049&creativeASIN=0735621314&adid=bb99d65d-188c-4309-9bb3-c49757f7d101" target=_blank>Visual Basic for Extensibility Library

Dim VBP As VBProject
Dim VBC As VBComponent
Dim VBMod As CodeModule

' -----------------------------------------------------------
' Coded by Shasur for http://vbadud.blogspot.com
'
-----------------------------------------------------------
Workbooks.Add
Set VBP = ActiveWorkbook.VBProject

Set VBC = VBP.VBComponents.Add(vbext_ct_StdModule)
VBC.Name = "MyMacro"

Set VBMod = VBC.CodeModule

VBMod.InsertLines 3, "Sub NewProc()" & Chr(13) & _
" Msgbox ""Welcome to VB Component Programming"" " & Chr(13) & _
"End Sub"

End Sub



Cheers
Shasur






Re: *** How can I add module code to a specific module? *** NEED HELP !!!!

sydney2000

Shasur,

Thanks for the reply and the snippet. However, I now run into another problem - A BIGGER PROBLEM. All the production workbooks are password protected including the VBAProject. As a result, I am unable to programmatically alter (in my case, add new module) to the VBAProject.

I have been doing lots of researching this morning and it does not appear one can programmtically unprotect the

VBAProject. I have seen examples where others are using the SendKeys() as the trick to accomplish this. I am experitmenting this SendKeys in VB.Net and I just can't get it to work. Does anyone know how to unprotect the VBAProject via code to allow updates Any other or better approach

Any help is greatly appreciated.

-Sydney






Re: *** How can I add module code to a specific module? *** NEED HELP !!!!

sydney2000

Shasur,

Thanks for the reply and the snippet. However, I now run into another problem - A BIGGER PROBLEM. All the production workbooks are password protected including the VBAProject. As a result, I am unable to alter the module

or in my case add a new module programmtically.

I have been doing lots of research this morning to see how this could be done and it does not appear one can unprotect

the VBAProject via code althought I have some examples where one uses SendKeys() as the trick to accomplish this. I am experiementing this SendKeys in VB.NET and I just can't get it to work. Does anyone know how to do this Any other way or better approaching in doing this

Any help you can offer is greatly appreciated.

-Sydney





Re: *** How can I add module code to a specific module? *** NEED HELP !!!!

NWAprog

If you are working from a project then the odds of adding a Module I believe are slim. I could be worng here, but one of the advantages of the ADP is that the Dbase is split, thereby putting all the records, tables, and modules at the back of the dbase structure, this is to maintain accuracy and prevent tampering. You need to have access to the tables and not just the forms. If you have this access, try holding shift when the dbase opens, that should open it in the standard mode. Of course I could be wrong, I'm still learning myself.