Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default macro for importing external data

I used the record macro function to create the following macro for importing
a text file into Excel 2007. How can I edit the macro to allow the selection
of the file location and type?

Here is the macro that the record macro function created:

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;E:\Recipe Converter Work\Tom-01.rcp",
Destination:=Range("$A$1" _
))
.Name = "Tom-01"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(2, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

This portion of the macro will break down the text file into two columns.
The deliminator is a :.

Any suggestions on how to change this so that I can reterive the necessary
files from anywhere?

Tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default macro for importing external data


Sub test()

fileToOpen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
If fileToOpen = False Then
MsgBox ("Cannot OPen File - exiting Macro")
Exit Sub
End If
'Original filename is commented out, use Dialog Box name instead
'FName = "E:\Recipe Converter Work\Tom-01.rcp"
FName = fileToOpen
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & FName, _
Destination:=Range("$A$1"))
.Name = "Tom-01"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(2, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

"Tom" wrote:

I used the record macro function to create the following macro for importing
a text file into Excel 2007. How can I edit the macro to allow the selection
of the file location and type?

Here is the macro that the record macro function created:

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;E:\Recipe Converter Work\Tom-01.rcp",
Destination:=Range("$A$1" _
))
.Name = "Tom-01"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(2, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

This portion of the macro will break down the text file into two columns.
The deliminator is a :.

Any suggestions on how to change this so that I can reterive the necessary
files from anywhere?

Tom

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 Execute macro after importing external data ranges Ed Finley Excel Programming 0 March 13th 08 12:20 AM
Importing External Data Fgbdrum Excel Discussion (Misc queries) 0 July 19th 07 05:12 PM
Importing External Data Donbenz1 Excel Discussion (Misc queries) 0 June 14th 07 09:36 PM
Importing External Data Paul Hammond Excel Discussion (Misc queries) 0 December 15th 05 10:28 PM
importing external data Al@n Excel Programming 3 November 30th 05 07:38 PM


All times are GMT +1. The time now is 01:18 PM.

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

About Us

"It's about Microsoft Excel"