So I work with CSV files and I need to open excel go to Data -> From text and format certain columns certain ways. I recorded a macro that does that but it always opens the file I used when recording the macro. How do I modify the macro so it opens the dialog box and let me choose a file each time? I found this piece of code on the internet but I don't know how to integrate it with my recorded macro in VBA.
Dim MyFile As String
MyFile = Application.GetOpenFilename()
Now how and where and what do I replace in the below macro (the code for which is created using the "record macro" button in excel)?
Sub random_name()
'
' random_name Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;MyFile = Application.GetOpenFilename()" _
, Destination:=Range("$A$1"))
.Name = "filename"
.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, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Thanks!