exporting sheets with buttons from master - VBA

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi,

I'm using the following code to export and save a number of sheets from a master workbook (rngTM contains the names of worksheets i wish to 'export'.)

One problem is that each sheet has a button with the task of refreshing the sheet..this works fine in the master but once i save in new location as an xlsm file, the buttons lose the code. I would like the newly created sheets to have the vba code within.. thanks in advance




Sub exportsheets()

Dim wbNew As Workbook
Dim rngTM As Range
Dim strPath As String




On Error GoTo Errorcatch


Application.ScreenUpdating = False


strPath = "C:\Users\pandoan\Desktop\test\"
Set rngTM = Sheets("Flow TM's").Range("A1")


Do
Sheets(Array("HC pivot TM data", rngTM.Value)).Copy
Set wbNew = ActiveWorkbook
With wbNew
.Sheets("HC pivot TM data").Visible = False
Application.Goto .Sheets(1).Range("B13"), True

Range("b2, F5:G5", "T3:U3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

wbNew.SaveAs strPath & rngTM & Format(Date, "ddmmmyyyy") & ".xlsm", FileFormat:=52

ActiveWorkbook.Close


End With
Set rngTM = rngTM.Offset(1, 0)
Loop Until IsEmpty(ActiveCell) = True

Application.ScreenUpdating = True


Errorcatch:
MsgBox Err.Description


End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Instead of trying to copy the button, why not just write a new button on your new sheet with something like:

Code:
ActiveSheet.Buttons.Add(1000, 10, 80, 18).Select
Selection.Name = "Refresh Button"
Selection.OnAction = "RefreshSheet"
Selection.Characters.Text = "Refresh Sheet"

And write a refresh sub to be called from the OnAction
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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