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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,223,708
Messages
6,174,006
Members
452,542
Latest member
Bricklin

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