Hi all, I am trying to create a variable option with my macro and currently have the following code. I have an error coming up at the beginning saying -sub or function not defined- Please help..
Rich (BB code):
'==========>>
Option Explicit
'---------->>
Sub PassVariables()
Call Tester(myYear:=2014, _
myQuarter:="Q4", _
myFolder:="TST", _
mySaveAsFolder:="Test", _
mySaveAsName:="1111", _
mySaveAsName2:="2222")
End Sub
'---------->>
Public Sub Main(myYear As Variant, myQuarter As String, _
myFolder As String, _
mySaveAsFolder As String, _
mySaveAsName As String, _
mySaveAsName2 As String)
Dim WB As Workbook
Dim WS As Worksheet
Dim spath As String
Dim sSaveAsPath As String
Dim sFilename As String
Dim sFullname As String
Dim aStr As String
aStr = myQuarter & " " & myYear
spath = "X:\specific folder\" & myYear & "\" & aStr & "\TMT\" & myFolder
sSaveAsPath = "X:\specific folder\" & myYear & "\" & aStr & "\TMT\" & mySaveAsFolder
sFilename = "ST " & aStr & ".xlsm"
sFullname = spath & "\" & sFilename
ChDir spath
Workbooks.Open Filename:=sFullname, Updatelinks:=0
ActiveCell.Offset(-1, 0).FormulaR1C1 = mySaveAsName
Set WS = ActiveSheet
Set WB = Workbooks.Add(xlWBATWorksheet)
WS.Range("A1:S84").Copy
WB.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ChDir sSaveAsPath
ActiveWorkbook.SaveAs Filename:=sSaveAsPath & "\" & mySaveAsName, _
FileFormat:=xlOpenXMLWorkbook, _
CreateBackup:=False
ChDir spath
Workbooks.Open Filename:=sFullname, Updatelinks:=0
ActiveCell.Offset(-1, 0).FormulaR1C1 = mySaveAsName2
Set WS = ActiveSheet
Set WB = Workbooks.Add(xlWBATWorksheet)
WS.Range("A1:S84").Copy
WB.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ChDir sSaveAsPath
ActiveWorkbook.SaveAs Filename:=sSaveAsPath & "\" & mySaveAsName2, _
FileFormat:=xlOpenXMLWorkbook, _
CreateBackup:=False
End Sub
'<<==========