The followings are my current steps
Access file exports a CSV file by Macro (VBA code)
The exported CSV file get modified by Macro (VBA code)
Right now, I'm executing the macro on Access (step 1)-> under the exported file, add the code and run (step 2)
I'd like to simplify the process.
Is it possible to by doing step 1, the step 2 code get added to the csv file and run?
Step 1 code
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim intFile As Integer
Dim strFilePath As String
Dim intCount As Integer
Dim strHold
strFilePath = "C:\temp\TEST.csv"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Import", dbOpenForwardOnly)
intFile = FreeFile
Open strFilePath For Output As #intFile
Do Until rst.EOF
For intCount = 0 To rst.Fields.Count - 1
strHold = strHold & rst(intCount).Value & "|"
Next
If Right(strHold, 1) = "|" Then
strHold = Left(strHold, Len(strHold) - 1)
End If
Print #intFile, strHold
rst.MoveNext
strHold = vbNullString
Loop
Close intFile
rst.Close
Set rst = Nothing
End Function
Step 2 code
Sub deleterows()
lastrow = Cells(Rows.Count, 4).End(xlUp).Row
For i = lastrow To 1 Step -1
If Cells(i, 4).Value < Date Then Rows(i).EntireRow.Delete
Next i
End Sub
note I prefer not to use windows scheduler to run Macro at a certain time.
My good reference has been so far Is it possible to automatically input VBA code when a new sheet is generated? & Dynamically insert macro into a new excel workbook & https://support.microsoft.com/en-us/kb/219905
I will try my best to be responsive! Please leave a comment for clarification. Thank you!