Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Bossing the Text Import Wizard about

I need to import a series of comma delimited text files into Excel. The
following chunk of code (pilfered from the macro recorder so it's probably
more wordy than it needs to be) does what I want but it relies on the name
and path of the text file to be hardcoded in.

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\admin\Desktop\Press Repor1.txt",
Destination _
:=Range("A2"))
.Name = "Press Repor1_2"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileTabDelimiter = True
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

What I need is for the user to be able to browse to the text file to be
imported, because it could be anywhere and called anything. Doing a File|open
and browsing to the text file means that the user would have to go through
the text import wizard, and I don't trust them to choose the right settings.

Can anyone provide a suggestion as to how I can allow the user to browse to
the text file and then for excel to get the text import settings from my code
rather than forcing the user to choose them? It's probably really simple but
I'm drawing a massive blank.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Bossing the Text Import Wizard about

You can prompt for a file like this:

Sub Demo()
Dim FName As Variant
FName = Application.GetOpenFilename("Text files(*.TXT),*.TXT")
If FName < False Then
MsgBox FName
Else
MsgBox "User cancelled"
End If
End Sub


--
Jim Rech
Excel MVP
"Katherine" wrote in message
...
|I need to import a series of comma delimited text files into Excel. The
| following chunk of code (pilfered from the macro recorder so it's probably
| more wordy than it needs to be) does what I want but it relies on the name
| and path of the text file to be hardcoded in.
|
| With ActiveSheet.QueryTables.Add(Connection:= _
| "TEXT;C:\Documents and Settings\admin\Desktop\Press Repor1.txt",
| Destination _
| :=Range("A2"))
| .Name = "Press Repor1_2"
| .FieldNames = True
| .RowNumbers = False
| .FillAdjacentFormulas = False
| .PreserveFormatting = True
| .RefreshOnFileOpen = False
| .RefreshStyle = xlInsertDeleteCells
| .SavePassword = False
| .SaveData = True
| .AdjustColumnWidth = False
| .RefreshPeriod = 0
| .TextFilePromptOnRefresh = False
| .TextFilePlatform = 850
| .TextFileStartRow = 1
| .TextFileParseType = xlDelimited
| .TextFileTextQualifier = xlTextQualifierDoubleQuote
| .TextFileTabDelimiter = True
| .TextFileCommaDelimiter = True
| .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
| 1, 1, 1, 1, 1, 1, 1, 1, 1, _
| 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
| 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
| , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
| .TextFileTrailingMinusNumbers = True
| .Refresh BackgroundQuery:=False
| End With
|
| What I need is for the user to be able to browse to the text file to be
| imported, because it could be anywhere and called anything. Doing a
File|open
| and browsing to the text file means that the user would have to go through
| the text import wizard, and I don't trust them to choose the right
settings.
|
| Can anyone provide a suggestion as to how I can allow the user to browse
to
| the text file and then for excel to get the text import settings from my
code
| rather than forcing the user to choose them? It's probably really simple
but
| I'm drawing a massive blank.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Bossing the Text Import Wizard about


How would I use the sub Jim just wrote, and reference the user define
filename&path in the rest of my code?

Thanks,
Kiera

--
Kieran102
-----------------------------------------------------------------------
Kieran1028's Profile: http://www.excelforum.com/member.php...fo&userid=1567
View this thread: http://www.excelforum.com/showthread.php?threadid=27009

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
How to Start Excel in Text Import Wizard for data import rlelvis Setting up and Configuration of Excel 0 July 10th 08 08:40 PM
Text Import Wizard dan Excel Worksheet Functions 2 August 8th 06 04:58 PM
Text Import Wizard vclemmons Setting up and Configuration of Excel 0 May 10th 06 10:22 PM
Text Import wizard Old Bob Excel Discussion (Misc queries) 2 December 21st 05 05:00 PM
Text Import Wizard Al Mackay Excel Programming 1 February 10th 04 10:48 PM


All times are GMT +1. The time now is 06:46 PM.

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"