Excel Nooby -> Importing a file..

Joined
Sep 24, 2007
Messages
2
Reaction score
0
Hey ppl,

I'm quite new to excel and visual basic so not that good with it yet.. I need to make a simple importing macro.. ok that wasnt so hard... But I need it to have a relative path, and for some reason it works when I use

Code:
	With ActiveSheet.QueryTables.Add(Connection:= _
		"TEXT;I:\Documents\Artikel.txt", Destination:=Range("A1"))

but when I use

Code:
	With ActiveSheet.QueryTables.Add(Connection:= _
		"TEXT;.\Artikel.txt", Destination:=Range("A1"))

it doesn't... can anyone help me out on this one.. As far as I know there are no other ways to import the file.

Also the second thing that got me is I need to get a file open dialog if the file can't be found.. Googled my ass off without any luck.. hope you can help me out.
 
Oke I got a bit further, I got the file open and am trying to use a variable instead of putting the path directly in there al the code is stole and edited abit so please tell me if its just total junk...



I'm trying to get it like this



Import file ./artikel.txt

if artikel.txt is not found open a file open dialog



Got this now



Code:
Dim sFileName As String

 

With Application.FileDialog(msoFileDialogOpen)

If .Show = False Then Exit Sub

 

sFileName = .SelectedItems(1)

 

End With

 

With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;" & sFileName, Destination:=Range("A1"))



But even when the file is there it uses the file open dialog instead of opening it instantly
 
Back
Top