Hello,
How can I insert code in ThisWorkbook module in Workbook_Open event? I would like something like code in code so I can write in my macro line by line what should be putted in Workbook_Open in ActiveWorkbook.
Good evening owiec
Try using this code :
Before you run it set a reference within the VBE to Microsoft Forms 2.0.Code:Sub test() Set wbcodemod = ActiveWorkbook.VBProject.VBComponents(ActiveWorkbook.CodeName).CodeModule Set codemod = ActiveWorkbook.VBProject.VBComponents(ActiveWorkbook.CodeName).CodeModule codemod.insertLines 1, "Public Sub Workbook_Open()" codemod.insertLines 2, "'** Put your lines of code in here **" codemod.insertLines 3, "End Sub" End Sub
Go to Tools > References, find and tck "Microsoft Forms 2.0 Object Library" and click OK.
HTH
DominicB
Now available : Ultimate Add-In 2007
Integrates directly into the Office Excel Ribbon
Download Ultimate Add-In v1.52 from www.dom-and-lis.co.uk
90+ Utilities, 200+ Sub utilities last updated 25th April 2008
Free!!
Hi,
Thanks for reply.
I get error Subscript out of range and it points toWhen I put something like MsgBox ActiveWorkbook.CodeName its returne blank window. Should it be like that?Set wbcodemod = ActiveWorkbook.VBProject.VBComponents(ActiveWorkbook.CodeName).CodeModule
I know that ActiveWorkbook is working cuz when I put MsgBox ActiveWorkbook.Name it returns aproperiate value.
Last edited by owiec; 03-12-2010 at 03:53 AM.
Hi owiec
Your profile states you are running XL2003. Is this still the case?
I tested the code last night on an XL2003 and it worked fine. I've tested it again this morning on a different machine and it still works fine.
Try running the macro in the attached file and let me know how it goes.
HTH
DominicB
Now available : Ultimate Add-In 2007
Integrates directly into the Office Excel Ribbon
Download Ultimate Add-In v1.52 from www.dom-and-lis.co.uk
90+ Utilities, 200+ Sub utilities last updated 25th April 2008
Free!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks