Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have been asked to write a macro that will import a text file into Excel (Office 2000) so that I can manipulate the data later. I used the macro recorder, and got a general idea of what I need to do, combined with topics in this forum. I put together this little macro, but I can't get it to work. The first part works great; it lets me choose the text file to import. The second part throws a "Run Time Error 1004: Application Defined or or object-defined error". The directory I am trying to pull data from is C:\Macros\Datafiles, and usually more than one text file exists in that directory, hence the need for the user to select the file. I have been playing around with statements for the past few days but cannot fix the problem. Can somebody please help? TIA
Sub GetFile() Dim fName As String fName = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt") If fName < "False" Then With ActiveSheet.QueryTables.Add(Connection:=fName, Destination:=Range("A1")) .Name = "DATA" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlFixedWidth .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "=" .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2) .TextFileFixedColumnWidths = Array(8, 13, 7, 11, 16) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
File Path - Macro | Excel Worksheet Functions | |||
Auto PRINT file path & Date on Excel work sheet ? | Excel Worksheet Functions | |||
Formula does not work after import of .txt file | Excel Discussion (Misc queries) | |||
Skipping Import Text File dialog in a Macro | Excel Discussion (Misc queries) | |||
Formula too long - new file path is shorter than old file path - Excel 2003 | Excel Worksheet Functions |