
Originally Posted by
Richard Buttrey
Hi
Sub YourSub
Dim stFName as String
stFName = Application.GetOpenFileName
With ActiveSheet.QueryTables.Add(Connection:= _
stFName, _
Destination:=Range("$A$1"))
'....etc
It seems to work well until the ....etc code starts.
I have written this way:
Dim stFName As String
stFName = Application.GetOpenFilename
Sheets("Data").Select
With ActiveSheet.QueryTables.Add(Connection:= _
stFName, _
Destination:=Range("$A$1"))
.Name = "data_267798_7267"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
What is marked in red text is causing a problem since it is hardcoded filename without the extension.
Can I extract the filenamn from the stFName in some way?
/Anders
Bookmarks