I've been trying to open text files into excel using vba. I want to access any text file and import it fast by clicking one button. I generated a vba code (with the help of a YT video: Automated Text Import in Excel with File Selection - The Easy Way - VBA - YouTube), but the issue is that when I run the code (press the import button), I only get a small portion of the text. Excel only reads up to a point where it finds a space between rows. It also makes each word go to a single cell for the "UW PID" file. Additionally, what can I add to my code so that when I click the "Import" button, I can simply select the cell where I want to import the file to in the same worksheet. in other words, use the same button, but import three different files in any selected cells. This link has the type of files I`m trying to import: https://www.dropbox.com/scl/fo/ipyyorn96vtx5zy7anr1a/h?dl=0&rlkey=9liwhym9gunbx9nanmzrnak97
Here is the code to help me with the import:
Sub ImportText()
Dim UWDT As Variant
Dim fileFilterPattern As String
Dim RawDust As Worksheet
Dim wbTextImport As Workbook
Application.ScreenUpdating = False
fileFilterPattern = "Text Files (*.txt; *.csv),*.txt;*.csv"
UWDT = Application.GetOpenFilename(fileFilterPattern)
If UWDT = False Then
MsgBox "No file selected."
Else
Workbooks.OpenText _
Filename:=UWDT, _
Origin:=437, StartRow:=1, 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)), TrailingMinusNumbers:=True
Set wbTextImport = ActiveWorkbook
Set RawDust = ThisWorkbook.Worksheets("Dust Raw Data")
wbTextImport.Worksheets(1).Range("A1").CurrentRegion.Copy RawDust.Range("A2")
wbTextImport.Close False
End If
Application.ScreenUpdating = True
[/CODE]End Sub