Insert a macro via vba

Margild8a

New Member
Joined
Nov 12, 2014
Messages
5
Good day,

i'm creating a macro that splits a master file into over 30 files, each of those files needs to have a macro that shows/hide columns for some of the sheets on them. i'm not able to figure out a way to add this code to each new file

Code:
If ActiveSheet.Columns("B:D").Hidden = True Then
[INDENT]ActiveSheet.Columns("B:D").Hidden = False[/INDENT]
Else
[INDENT]ActiveSheet.Columns("B:D").Hidden = True[/INDENT]
End If

Thanks in advance for your help
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I think you need to Export the Macro then Import it into the new file.

This is what I did but I first needed to set up the Path where to export the macro it's called strTempFile1 in the example:

'Copy Module from ThisWorkBook to the path and folder of ThisWorkBook
MSRMaster.VBProject.VBComponents("Active_Customer_Filter").Export strTempFile1

'Copy the Module we saved earlier from ThisWorkBook to the New Workbook
Application.VBE.ActiveVBProject.VBComponents.Import (strTempFile1)
 
Upvote 0
I think you need to Export the Macro then Import it into the new file.

This is what I did but I first needed to set up the Path where to export the macro it's called strTempFile1 in the example:

'Copy Module from ThisWorkBook to the path and folder of ThisWorkBook
MSRMaster.VBProject.VBComponents("Active_Customer_Filter").Export strTempFile1

'Copy the Module we saved earlier from ThisWorkBook to the New Workbook
Application.VBE.ActiveVBProject.VBComponents.Import (strTempFile1)


Thank you i'll try it.
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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