I use a batch file with the following code:
cscript DeleteDuplicateDataMacro.vbs "C:\Users\techadmin\Documents\DeleteDuplicateDataMacro\DeleteDuplicateDataMacro.xlsm
Which runs this VBScript code:
Dim args, objExcel
Set args = wScript.Arguments
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open args(0)
objExcel.Visible = True
ObjExcel.Run "DeleteDuplicateData"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
Which opens my Macro-Enabled Workbook and runs the following Macro:
Sub DeleteDuplicateData()
'
' DeleteDuplicateData Macro
'
'
Application.DisplayAlerts = False
**With ActiveSheet.QueryTables(1).Refresh _
.Connection = "TEXT;C:\Users\techadmin\Documents\Sapphire Report Agent\Sapphire_NK_Export.csv"**
'.CommandType = 0
.Name = "Sapphire_NK_Export"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-9
ActiveSheet.Range("$A$1:$Q$2500").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), Header:=xlYes
ActiveSheet.Range("$A$1:$Q$2500").RemoveDuplicates Columns:=17, Header:=xlYes
ChDir "C:\Users\techadmin\Documents\Sapphire Report Agent"
ActiveWorkbook.SaveAs Filename:="C:\Users\techadmin\Documents\Sapphire Report Agent\Sapphire_NK_Export", FileFormat:=xlCSV, CreateBackup:=False
ActiveCell.FormulaR1C1 = "STATE_STUDENT_ID"
Range("A1:Q2500").Select
Range("A1").Activate
Selection.ClearContents
Range("A1").Select
ChDir "C:\Users\techadmin\Documents\DeleteDuplicateDataMacro"
ActiveWorkbook.SaveAs Filename:="C:\Users\techadmin\Documents\DeleteDuplicateDataMacro\DeleteDuplicateDataMacro", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
Every few times this sequence is run, my Macro-Enabled Workbook's file size gets a few Kilobytes larger. This increases exponentially. Once it gets around the 30,000 Kilobyte range then my other Workbook (the one that is getting imported during this macro, then edited and saved back to its original location) starts having it's columns duplicated.