LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How do I insert a variable for the file/path in aQuery Table?

I'm automating a workbook for some clients, and the process begins with a
data download from their local Multiple Listing Service (MLS). The code that
works is below. What I've been trying to do is find a means for replacing the
hard coded file/path -- C:\CMA\CMAData.csv -- with a variable passed from an
input box. Building the string is easy, but Excel doesn't accept the string
on execution of the code. The error message is : Run Time Error: 1004
Application-Defined or object- defined error. My suspicion is that this can't
be done by passing avariable into "QueryTables.Add."

My goal is to allow users to specify the path and file name on the fly
rather than forcing them into a fixed path and file.

Any ideas would be appreciated, and I thank you in advance for reading this.

Sub ImportCMAData()

Sheets("Data").Select

With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\C MA\CMAData.csv", _
Destination:=Range("A1"))
.Name = "CMAData_1"
.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 = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

End Sub

 
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 do I insert the directory path in my Excel file? Insert a Directory Path in Header/Footer Excel Worksheet Functions 2 February 4th 05 09:23 PM
Save to Path & Variable file name Otto Moehrbach[_6_] Excel Programming 4 September 2nd 04 10:44 PM
Insert path and file name in excel 2000 Julie Excel Programming 2 January 22nd 04 04:05 PM
Naming a variable in a file path Ron[_13_] Excel Programming 1 October 19th 03 02:56 AM
Using a variable string in a file save path Ron[_13_] Excel Programming 1 October 16th 03 08:29 PM


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