Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy a macro to a new worksheet in excel

Status
Not open for further replies.

20851423

Technical User
Feb 2, 2008
1
AU
I have a master workbook in excel that constists of some macros on saving I make a copy of a worksheet and save that work sheet as a new workbook. What I would like to do is copy a macro across to the newly saved workbook
Here is a copy of the macro I use to save the worksheet

Sub SaveReport()

'Copy worksheet
Application.ScreenUpdating = False
Dim wb As Workbook
Dim NewShtName As String
NewShtName = "Charge Sheet " & RN

Sheets("Charge sheet").copy
Set wb = ActiveWorkbook
wb.Sheets("Charge sheet").Name = NewShtName

File_To_SaveAs_Name = Application.GetSaveAsFilename( _
fileFilter:="Excel files (*.xls), *.xls")
ActiveWorkbook.SaveAS Filename:=File_To_SaveAs_Name, CreateBackup:=False
Workbooks("charge out sheet.xlt").Close

End Sub

And a copy of the macro I wish to copy to the new workbook:

Sub InsertRow()
With ActiveSheet
.Unprotect Password:="password"
Dim Rng, n As Long, k As Long
Application.ScreenUpdating = False
Rng = InputBox("Enter number of rows required.")
If Rng = "" Then Exit Sub
Range(ActiveCell, ActiveCell.Offset(Val(Rng) - 1, 0)).EntireRow.Insert
'need To know how many formulas To copy down.
'Assumesfrom A over To last entry In row.
k = ActiveCell.Offset(-1, 0).Row
n = Cells(k, 256).End(xlToLeft).Column
Range(Cells(k, 1), Cells(k + Val(Rng), n)).FillDown
.Protect Password:="password"
End With
End Sub

Can any one help on this
 
The easiest way is probably to copy your worksheet to a workbook already containing the macro and then Save As.

Gavin
 
I am sure there have been plenty of threads in the VBA forum on the topic. Suggest you have a search there. Also have a look at this:

To pursue this you should re-post in the VBA forum Forum707.

Regards,

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top