Split XLSM-file into pieces and keep source model

Gerbie1

New Member
Joined
May 18, 2016
Messages
2
Hi!

I have a challenge... I have a masterfile with sales-information in a database and nicely layout in pivot tables. I created a macro to split this information by account so its shows the pivot table with the sales data. My issue is - on these nicely layout pivottable sheets, I have some macro-buttons to "show" and "hide" detail, "reset" filters etc...

When I run my macro the new file is saved as an XLSX and the macro-buttons will not work in the individual file. So my question is - how can I make sure that the "Module" is also being taken over into the newly create file so that the buttons still work fine? Secondly, how do I get it saved as XLSM? (so that the macro works).

Code:
Sub Run_StratAccountRep()'
 SAD = ActiveWorkbook.Name
 Sheets("vlookup").Select
 a = 1
 SA = Cells(a + 1, 4)
 
MMM = Cells(2, 2)


If MsgBox("Are you sure you want to continue, all previous reports (with same name) will be overwritten", vbOKCancel) = vbCancel Then
Exit Sub
Else
End If




If Dir("C:\Strat Account\") = "" Then
    MkDir Path:="C:\Strat Account\"


End If


Do While Not SA = "END"


     Windows(SAD).Activate
     
      SA = Cells(a + 1, 4)
              
             b = b + 1
        
            
           Sheets("db1").Select
           Selection.AutoFilter
           Range("B11").Select
           ActiveSheet.Range("$A$4:$Q200000").AutoFilter Field:=8, Criteria1:= _
           SA
           Cells.Select
           Selection.Copy
           Sheets("DBpivot").Select
           Range("a1").Select
           ActiveSheet.Paste
           Sheets("1- Strat Acc").Select
           ActiveWorkbook.RefreshAll


        Windows(SAD).Activate
        Sheets(Array("1- Strat Acc", "2 - Strat Acc by Rgn-Cntry", "3 - End User Report") _
        ).Select
        Sheets(Array("1- Strat Acc", "2 - Strat Acc by Rgn-Cntry", "3 - End User Report") _
        ).Copy
    
    
    ' Sheets("1- Strat Acc").Activate
     '   Sheets("pivot").Copy
        
        SAR = ActiveWorkbook.Name


        Range("a1").Select


     Application.DisplayAlerts = False


     ActiveWorkbook.SaveAs Filename:="c:\STRAT Account\" & SA & MMM
     Application.DisplayAlerts = True
     ActiveWorkbook.Close
     Sheets("vlookup").Select
     a = a + 1
     SA = Cells(a + 1, 4)
Loop


Application.ScreenUpdating = False
End Sub


Thanks for your views!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hello and welcome to The Board.
Could it be the following?
Code:
ActiveWorkbook.SaveAs Filename:="c:\STRAT Account\" & SA & MMM & ".xlsm"
 
Upvote 0
Thanks for your reply! Yes - tried that...
The issue is that this will not bring over the VBA/Module1 from my Masterfile to my newly created file.... so I guess I need a code/way to ensure that the Marco functions of Module1 are also copied into the new file...

Any solutions for that?

thanks!
 
Upvote 0

Forum statistics

Threads
1,216,747
Messages
6,132,486
Members
449,729
Latest member
davelevnt

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