help with ActiveSheet.QueryTables.Add Connection:

U

uriel78

I'm just trying to import a txt file (little by little i'm improving...)
Below there is the first part of the code that do the input of a specific
file
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and
Settings\Roby\Documenti\Università\tesi\Modelli2\Edificio
esistente\Base\3PO_altezze_Y_prototipo2_OUTDATI.txt" _
, Destination:=Range("A1"))
.Name = "3PO_altezze_Y_prototipo2_OUTDATI5"
FieldNames = True
.RowNumbers = False
............................. .
.............................



Now, I wish I can use a dialog form instead of specifying the path directly
in the code as above written

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and
Settings\Roby\Documenti\Università\tesi\Modelli2\Edificio
esistente\Base\3PO_altezze_Y_prototipo2_OUTDATI.txt" _
, Destination:=Range("A1"))

I think may it is possible to use somthing as Application.GetOpenFilename to
indicate the connection path...In other terms, as I have to do import
procedure for a lot of *.txt files, I don't want to have to specify
explicitally the path for every file...It will be better to be able to use a
graphic interface that allow me to browse for the file....

Thanks in advance for every help...!
 
T

Tom Ogilvy

If you want to use GetOpenfilename to specify the file:

Dim fName as Variant
fname = Application.GetOpenFilename()
if fname <> False then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fName _
, Destination:=Range("A1"))

............................................
End if
Otherwise, it is unclear what you are saying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top