Ask the Expert

How do I create a macro that can create a file that includes another macro in it?

I currently have a macro in Excel that creates an Excel template by importing a text file into the spreadsheet and then saving it as a template. I want the template to have a macro in it that does something different. How do I create a macro that can create a file that includes a macro in it?

Requires Free Membership to View

Interesting question. What you'd have to do is write a macro to parse up your text file and as part of that macro, write the macro you want to write. Is that recursive enough for you? What you are going to have to do is manipulate the Visual Basic Editor 6.0 Object Model to drive your macro creation. In Office XP Developer, the Visual Basic Editor 6.0 Object Model is discussed under the Microsoft Office XP Developer Object Model Guide, Shared Components section of the documentation. The ins and outs are in the VBOB6.CHM help file. When you install Office XP, make sure to check that you want all the programming help/VBA files installed so you get it installed.

This was first published in December 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: