I have the following VBA code that works great in Excel. I would like to be able to run this code from within my Access DB. Is it possible?
(I dont even need to use the template. I just want to take a Master File and create individual excel files based on column A. Whenever column A changes, create a new file).
Code:
Sub Test()
Dim Sh As Worksheet: Set Sh = Worksheets("MasterFile_All")
Dim LR As Long: LR = Sh.Range("A" & Rows.Count).End(xlUp).Row
Dim Rng As Range: Set Rng = Sh.Range("A2:A" & LR)
Dim c As Range
Dim List As New Collection
Dim Item As Variant
Dim WB As Workbook
Application.ScreenUpdating = False
On Error Resume Next
For Each c In Rng
List.Add c.Value, CStr(c.Value)
Next c
On Error GoTo 0
Application.DisplayAlerts = False
Set Rng = Sh.Range("A1:O" & LR)
For Each Item In List
Set WB = Workbooks.Add(template:=ThisWorkbook.Path & "\CLOSED ALL TEMPLATE.xlt")
Rng.AutoFilter Field:=1, Criteria1:=Item
Sh.UsedRange.SpecialCells(xlCellTypeVisible).Copy WB.Worksheets(1).Range("A5")
Rng.AutoFilter
With WB
.SaveAs "C:\Open Projects\Reports\" & Item & "\June 2011\Individual Files_" & Item & ".xlsx"
.Close
End With
Next Item
Sh.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub