Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text to excell without especifying path

i do this to import a file, but i have to specify the path:
With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;C:\DATA.txt", _
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 Sub

how do i do this so the user can choose the document, a different pat
and name every time?

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Importing text to excell without especifying path

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

--
Regards,
Tom Ogilvy


"cecilia12345" wrote in message
...
i do this to import a file, but i have to specify the path:
With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;C:\DATA.txt", _
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 Sub

how do i do this so the user can choose the document, a different path
and name every time?!


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text to excell without especifying path

are you sure that fName should be string? because every time i get t
the
--
" With ActiveSheet.QueryTables.Add(Connection:= _
NombreArchivo, _
Destination:=Range("A1")) " - part

it stops!!!!
the alert it gives me says : "error defined by application or object

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text to excell without especifying path

oh now i realized what the problem was.. i just had to add
NombreArchivo = "TEXT;" & NombreArchivo
after the condition...!!!
well, just in case somebody wanted to know...

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Importing text to excell without especifying path

Yes, that was my oversight. Sorry about that.

--
Regards,
Tom Ogilvy

"cecilia12345" wrote in message
...
oh now i realized what the problem was.. i just had to add
NombreArchivo = "TEXT;" & NombreArchivo
after the condition...!!!
well, just in case somebody wanted to know....


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text to excell without especifying path

ok, thanks for your help!!!!!!

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text to excell without especifying path

Can someone please explain what the outcome of the "nombre...."
modification was here. I've been playing around with it but cant seem
to get this macro working!

Many thanks


---
Message posted from http://www.ExcelForum.com/

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Importing text to excell without especifying path

Turn on you macro recorder and do
Data=Get External Data and select import text file . . .

--
Regards,
Tom Ogilvy



"ian123" wrote in message
...
Can someone please explain what the outcome of the "nombre...."
modification was here. I've been playing around with it but cant seem
to get this macro working!

Many thanks


---
Message posted from http://www.ExcelForum.com/



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
Importing External Data - Can we specify the full path jay Setting up and Configuration of Excel 2 November 28th 07 04:11 PM
Importing data from excell to access. Tobes Excel Discussion (Misc queries) 2 November 14th 07 08:31 AM
importing into Excell 2000 Doug Woodward Excel Discussion (Misc queries) 4 February 16th 06 07:45 PM
How to import a path/filename when importing data into an XML list cxparker Excel Worksheet Functions 0 December 7th 04 10:13 PM
S.O.S :importing excell data into word villi Excel Discussion (Misc queries) 0 November 25th 04 08:37 PM


All times are GMT +1. The time now is 10:17 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"