I cannot release all of the details for the ScrubForImport Macro, however, it's code executes correctly and is not involved with the opening or saving of the files. All the data I am trying to automate is saved in csv files called wb1.csv, wb2.csv, etc up to wb61.csv. I'm trying to run this same ScrubForImport macro on all of them and save them all as new .csv files.
The main Macro that gets run:
Public TotalQtySold As Long, BookCount As Integer, CurrentBook As Integer, CurBookStr As String, CurWorkSheetStr As String, CurBookSaveStr As String
Sub AutoScrub()
'This sub will read through all workbooks for a bulk import. They are named wb1.csv, wb2.csv etc.
BookCount = 2
CurrentBook = 1
CurBookStr = "wb" & CurrentBook & ".csv"
CurWorkSheetStr = "wb" & CurrentBook
CurBookSaveStr = "wb" & CurrentBook & "_scrubbed.csv"
'Loop through all csv files to scrub
For CurrentBook = 1 To BookCount
Call OpenWorkBooks
Call ScrubForImport
Call SaveWorkBooks
CurrentBook = CurrentBook + 1
Next
End Sub
This is the OpenWorkBooks Macro:
Sub OpenWorkBooks()
'Opens all workbooks in a folder, copies their contents to this workbook, scrubs the data and saves it as a csv for import into Access
Dim wsopen As Worksheet
'Manually set BookCount here
Workbooks.Open Filename:="C:\Exports\" & CurBookStr
MsgBox ("WB Opened")
'Select and Copy sheet from a RIS CSV export
Workbooks(CurBookStr).Activate
Worksheets(CurWorkSheetStr).Activate
ActiveSheet.Cells.Copy
MsgBox ("WS Copied")
'Select and Paste sheet to BulkProcessor.xlsm
Workbooks("BulkProcessor.xlsm").Activate
Worksheets("Import").Activate
Range("A1").Select
ActiveSheet.Paste
MsgBox ("WS Pasted")
'Close other WB to save RAM
Workbooks(CurBookStr).Close
MsgBox ("WB Closed")
End Sub
This is the SaveWorkBooks Macro:
Sub SaveWorkBooks()
'This sub will save the scrubbed data as a CSV for import into Access
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Scrubbed\" & CurBookSaveStr, FileFormat:=xlCSV, _
CreateBackup:=False
'ActiveWorkbook.SaveCopyAs Filename:="C:\Scrubbed\" & CurBookSaveStr, FileFormat:=xlCSVWindows
End Sub
Bookmarks