1

I have a question regarding this link, more specific Using a query table

With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;***C:\Sample.txt***", Destination:=Range("$A$1") _ )

In the example C:\Sample.txt is entered statically. How would you make this dynamic and let the user select the file?

2
  • OH!! How could I miss that? It was right there. Thanks a lot. Commented Oct 15, 2013 at 7:49
  • @t.thielemans post that as the answer to have it upvoted and delete the comment after. Whe he does this Punit will need to accept it Commented Oct 15, 2013 at 8:34

2 Answers 2

1

I presume you're looking for this function;

FileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
Sign up to request clarification or add additional context in comments.

1 Comment

I was using this function already. But while using the variable name 'filename' I actually missed the '&' to be used before variable name and therefore was getting an error.
0

Try the below code:

Public Browse(ByVal i as Integer,ByVal j as Inetger)
   Application.EnableCancelKey=xlDisabled
   Cells(i,j)=Application.GetOpenFileName(,,,,"Select File",,false) 
End Sub

Sub BrowseFile
   Call Browse(8,9) 'Cell no. 
End Sub

The BrowseFile can be assigned to the ActiveX Controls Object which can be provided in front end.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.