Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Open several text files using a macro
Hello:
I have a folder that contains several text files (.txt). I want to open them all at the same time usng a macro. If my code looks something like this to open one file, how can I use this macro to open several files in one click. I would create a button and write the code behind the button. Thanks, Jade Code Sub Test_Macro() Dim myFileName As Variant fileName = Application.GetOpenFilename(filefilter:="Text Files, *.Txt", _ Title:="Choose File") If myFileName = False Then MsgBox "Cancelled" End If 'the next couple of lines don't work With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Documents and Settings\JGraham\Desktop\" & fileName, _ Destination:=Range("A1")) .Name = fileName .FieldNames = True .RowNumbers = False .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = xlWindows .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) .Refresh BackgroundQuery:=False End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
error when running cut & paste macro | Excel Worksheet Functions | |||
Macro that stores all sheets as tab-delimited text files | Excel Discussion (Misc queries) | |||
CSV formatted files open odly in Excel 2000 | Excel Discussion (Misc queries) | |||
file open via IE hyperlink causes already open files to shrink and tile | Setting up and Configuration of Excel | |||
How do I change macro text with another macro? | Excel Discussion (Misc queries) |