EliseFreedman
Programmer
Hi There
I am attempting to import a file into an existing workbook using the code below. I have used similar code in another workbook without any problems but this time round I am getting the following error. Does anyone know what is causing this?
The code that I am using is below
I am attempting to import a file into an existing workbook using the code below. I have used similar code in another workbook without any problems but this time round I am getting the following error. Does anyone know what is causing this?
Code:
The destination range is not on the same worksheet that the query table is being created on
The code that I am using is below
Code:
Private Sub CommandButton2_Click()
'
Sheets("RFV").Select
ActiveSheet.Rows("1:3").Select
Selection.ClearContents
ActiveSheet.Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;H:\RFV.csv", Destination _
:=Range("A1"))
.Name = "RFV"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:A").ColumnWidth = 18.29
End Sub