View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mindblower Mindblower is offline
external usenet poster
 
Posts: 1
Default Error when trying to use QueryTables.Add

I´ve got some problems when I try to use QueryTables.Add on a sheet tha
I previously has created with :
Worksheets.Add(After:=Worksheets(Worksheets.Count) )

I get the error Run-Time error '5'

I have tried both:
With ActiveSheet.QueryTables.Add...........
and
With Sheets(MyBacklogname).QueryTables.Add......

Code:

MyBacklogname = "Outfile_B" & Sheets("Parametrar").Cells(7, 2).Value
"_backlog"
Set oSheet = Worksheets.Add(After:=Worksheets(Worksheets.Count) )
With oSheet
.Name = MyBacklogname
End With

Sheets(MyBacklogname).Activate
Sheets(MyBacklogname).Select

MyConnection = "TEXT;" & ActiveWorkbook.Path & "\" & MyBacklognam
& ".txt"
With ActiveSheet.QueryTables.Add(Connection:=MyConnecti on
Destination:=Range("D2"))
.Name = "Outfile_Pplan"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
'.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1
1)
.Refresh BackgroundQuery:=False
End With



\Someone help me :

--
Message posted from http://www.ExcelForum.com