Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Macro that stores all sheets as tab-delimited text files [email protected] Excel Discussion (Misc queries) 2 February 14th 06 04:02 PM
CSV formatted files open odly in Excel 2000 Janski Excel Discussion (Misc queries) 3 November 24th 05 07:58 PM
file open via IE hyperlink causes already open files to shrink and tile Marc Setting up and Configuration of Excel 0 May 4th 05 08:13 PM
How do I change macro text with another macro? Eric Excel Discussion (Misc queries) 4 April 27th 05 11:20 PM


All times are GMT +1. The time now is 08:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"