In the code below, it is failing at the "FORMAT TEMPLATE" comment. I get a run time error 1004. What I am doing is - I am closing the previous window (from copying the template) and pasting it into the good workbook. I don't think I am switching workbooks properly.
Sub BBUorders()
'OPEN TEMPLATE
Dim sPath As String, sFile As String
Dim wb As Workbook
sPath = "C:\Users\douglas.futato\Desktop\"
sFile = sPath & "BBU_CMD_TEMPLATE.xlsx"
Set wb = Workbooks.Open(sFile)
'COPY TEMPLATE PASTE IN BBU DOC
Dim tmplt As Workbook
On Error Resume Next
Set tmplt = Workbooks("BBU_CMD_TEMPLATE.xlsx")
If tmplt Is Nothing Then
MsgBox "Template file needs to be open..."
Exit Sub
End If
On Error GoTo 0
With ThisWorkbook
tmplt.ActiveSheet.Copy After:=.Sheets(.Sheets.Count)
End With
'CLOSE TEMPLATE
Windows("BBU_CMD_TEMPLATE.xlsx").Activate
ActiveWindow.Close False
'FORMAT TEMPLATE --------- THIS IS WHERE IS BOMBS OUT
ThisWorkbook.Activate
Worksheets(“Sheet3”).Activate
ActiveCell.Offset(-3, -8).Range("A1:H1").Select
Selection.AutoFilter
Cells.Replace What:="[BBU_CMD_TEMPLATE.xlsx]Price List", Replacement:=Sheet1.Name, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ActiveSheet.Range("$A$1:$H$61").AutoFilter Field:=6, Criteria1:="0"
Rows("2:100").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-18
ActiveSheet.Range("$A$1:$H$18").AutoFilter Field:=6
ActiveSheet.Range("$A$1:$H$18").AutoFilter Field:=7, Criteria1:="0"
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$H$17").AutoFilter Field:=7
Range("E2").Select
ActiveCell.FormulaR1C1 = "=R[-1]C+1"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E50"), Type:=xlFillDefault
Range("E2:E21").Select
Range("I1").Select
ActiveSheet.Range("$A$1:$H$50").AutoFilter Field:=1, Criteria1:="="
Rows("8:100").Select
Selection.Delete Shift:=xlUp
Range("A2:H2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveSheet.Range("$A$1:$H$7").AutoFilter Field:=1
Range("A1").Select
End Sub