Public phrase As String
Public phrase2 As String
Public fname As String
Public phrase3 As String
Public ws As Worksheet
Public irow As Long
Public cell As Range
Sub cleanup()
Set ws = Sheets("sheet1")
irow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In ws.Range("a1:aa" & irow).Cells
cell.Value = ""
Next cell
End Sub
Sub Macro1()
phrase = Environ("userprofile")
phrase2 = phrase & "\desktop\*.archive"
If Len(Dir(phrase2)) > 0 Then
Call filefinder
phrase = "TEXT;" & phrase2
GoTo step2
Exit Sub
Else:
MsgBox "No Archive file found on the desktop. Exiting."
End If
Exit Sub
step2:
Set ws = Sheets("sheet1")
With ActiveSheet.QueryTables.Add(Connection:= _
phrase, Destination:=Range( _
"$A$1"))
.Name = fname
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ws.Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
(20, 1), Array(21, 1), Array(22, 1)), TrailingMinusNumbers:=True
With ws
.Columns("J:J").NumberFormat = "0000000000"
.Columns("P:P").NumberFormat = "00000000000000"
.Columns("A:AA").AutoFit
End With
ws.Columns("V:V").Select
Range("V76").Activate
Selection.Replace What:="costco", Replacement:="SHP", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
phrase = Environ("userprofile")
phrase2 = phrase & "\desktop\Commerce Hub"
ChDir phrase2
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=phrase2 & "\orderfile.csv", _
FileFormat:=xlCSV, CreateBackup:=False
Application.Quit
End Sub
Sub filefinder()
fname = Dir(phrase2)
Do While fname <> ""
phrase3 = phrase & "\desktop\" & fname
fname = Dir()
Loop
phrase2 = phrase3
End Sub