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?

Community
  • 1
  • 1
Punit
  • 11
  • 2
  • OH!! How could I miss that? It was right there. Thanks a lot. – Punit Oct 15 '13 at 07: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 – Katana24 Oct 15 '13 at 08:34

2 Answers2

1

I presume you're looking for this function;

FileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
Community
  • 1
  • 1
CustomX
  • 9,948
  • 30
  • 85
  • 115
  • 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. – Punit Oct 15 '13 at 09:10
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.