Inserting a sub into a new page using VB/Macros

Kabasauls

New Member
Joined
Jul 12, 2012
Messages
24
Hello,

I wrote a code that creates new pages based on a template. I found that I need to add three Subs() to every page that is created using this code. I have never done this before and after seraching for an answer, came out empty handed.

I am looking for a way to create a page and add code using my previously written code.

This is what I've tried to come up with so far.

Code:
Sub AddCode()

Dim sCode As String

   sCode = "sub VBAMacro()" & vbCr & " msgbox ""VBA Macro called"" " & vbCr & "end sub"
   'find a way to insert this code (String) into new page
      
End Sub

Thank you for your time.
 
No problem.:)

I could have posted code to programatically add code but to use that you need to change certain security settings in Excel.

If you are still interested in doing that check here.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top