L
Legacy 352679
Guest
Hey everyone,
I received a lot of help here before so I thought I would post another question which I'm unsure on.
I have recorded a macro that converts a text file into a spreadsheet. However, it has obviously only recorded the specific file path and name of said text file. What I would like to achieve is to have the macro prompt the user to choose the specific text file from the file path (i.e. opening up the window and letting the user double click the specific text file each time the macro is run). The ultimate goal is to have the spreadsheet be used as a template stored in the file path in which all text data will be downloaded into, and then just open the spreadsheet, run macro and then choose the desired text file to convert (the text files will all have different names).
As an additional request, is it possible to prompt the user to Save As a macro enables textbook after this macro is run, just so the user doesn't keep running it and preventing the loss of data?
Alternative: Is it possible to create a macro to do this for multiple text files at the same time, but within individual template files? For example, I have Text File A and Text File B. Run macro from the template and have it work on both text files but have two templates open so the user can continue to run other respective macros.
The current template has additional macros that I would like to run afterwards, hence why I would require it to be in separate files, I'm just not sure that this could be done since the name of the template file is [Climate Data Converter Template], and you can't have two of the same file name open at once. - This is not essential, but it might be something I'm curious about exploring later on.
Recorded code so far:
Please forgive any errors in the code as I unfortunately had to type it out manually.
Cheers for any feedback as I'm still a bit new to VBA and only learning the basics through Google and Recorder.
I received a lot of help here before so I thought I would post another question which I'm unsure on.
I have recorded a macro that converts a text file into a spreadsheet. However, it has obviously only recorded the specific file path and name of said text file. What I would like to achieve is to have the macro prompt the user to choose the specific text file from the file path (i.e. opening up the window and letting the user double click the specific text file each time the macro is run). The ultimate goal is to have the spreadsheet be used as a template stored in the file path in which all text data will be downloaded into, and then just open the spreadsheet, run macro and then choose the desired text file to convert (the text files will all have different names).
As an additional request, is it possible to prompt the user to Save As a macro enables textbook after this macro is run, just so the user doesn't keep running it and preventing the loss of data?
Alternative: Is it possible to create a macro to do this for multiple text files at the same time, but within individual template files? For example, I have Text File A and Text File B. Run macro from the template and have it work on both text files but have two templates open so the user can continue to run other respective macros.
The current template has additional macros that I would like to run afterwards, hence why I would require it to be in separate files, I'm just not sure that this could be done since the name of the template file is [Climate Data Converter Template], and you can't have two of the same file name open at once. - This is not essential, but it might be something I'm curious about exploring later on.
Recorded code so far:
VBA Code:
Sub Macro1()
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT[This is the file path and text file name]" 'The file path would be the same, but the text file name would be different each time _
, Destination:=Range("$A$1"))
'.CommandTyoe = 1 'For some reason when I null this section of code it works perfectly fine, so I'm not sure if this part is necessary even though it was recorded?
.Name = "[Would change each time]"
.FieldNames = True
.RowNumbers = False
.RefreshOnFileOpen= False
.RefreshStyle = xlInsertDeletedCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStarRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifiedDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Please forgive any errors in the code as I unfortunately had to type it out manually.
Cheers for any feedback as I'm still a bit new to VBA and only learning the basics through Google and Recorder.