C
Charles
I have enclosed below a small portion of a macro whose sole function is to
copy and paste the data from a master spreadsheet to a new excel file.
The challenge we are having is if the name of the master spreadsheet is not
"filename.xls" the routine does not work.
I am looking for assistance in how ANY file name can be used and the macro
knows to simply look in the active file. Please note that the macro uses 4
tabs within the work sheet.
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+z
'
Workbooks.Add
Windows("FILENAME.xls").Activate
Sheets("TAB1").Select
Range("A1:C24").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.PageSetup.PrintArea = "$A$1:$C$24"
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "TAB1"
Range("A1:C24").Select
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "$A$1:$C$24"
End With
End Sub
copy and paste the data from a master spreadsheet to a new excel file.
The challenge we are having is if the name of the master spreadsheet is not
"filename.xls" the routine does not work.
I am looking for assistance in how ANY file name can be used and the macro
knows to simply look in the active file. Please note that the macro uses 4
tabs within the work sheet.
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+z
'
Workbooks.Add
Windows("FILENAME.xls").Activate
Sheets("TAB1").Select
Range("A1:C24").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.PageSetup.PrintArea = "$A$1:$C$24"
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "TAB1"
Range("A1:C24").Select
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "$A$1:$C$24"
End With
End Sub