I want to create a code module with VBA. When I already have a code module I know that I can set it using:
Set cdmdl = wbk.VBProject.VBComponents(codeModuleName).CodeModule
But if the code module does not exist, how can I create it?
I've tried a few lines like:
Set cdmdl = new.wbk.VBProject.VBComponents(codeModuleName).CodeModule
Set cdmdl = create.wbk.VBProject.VBComponents(codeModuleName).CodeModule
But they haven't worked. I've also Googled, but this doesn't seem like a popular topic.
This worked for me:
You can also
AddFromFile
if you have a .bas file you've exported and you want to load into a workbook.