Import macro Bombs Out

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
I have the following code that I use on a number of spreadsheets, For some reason on the latest one the macro bombs at the

With Selection.QueryTable

Line. Can anyone help me out?

Private Sub btnImportData_Click()
Me.Hide
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Sheets("Info").Visible = True
Sheets("Info").Select
Range("H14,H11,N31:N32,G41").Value = Null 'Plant,Model Yr, EC Lvl, EC Date, Notes
Range("N13").Select 'False Word
Selection.Copy
Range("A25:A34").Select ' Report Selectors
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Selection.Copy
Range("W2:W17").Select ' Purchased Items Direct
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Range("W20:W44").Select ' Material Auto?
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Range("X20:X44").Select ' Steel or Aluminum?
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("A1").Select
Sheets("Info").Visible = False
Sheets("Fordtabs1").Visible = True
Sheets("Fordtabs1").Select
Range("M2").Value = Null 'Report Date
Range("A1").Select
Sheets("Fordtabs1").Visible = False
btnClear_Click 'Clears Import sheet
Application.ScreenUpdating = False
Sheets("Import").Visible = True
ChDrive "S"
ChDir "S:\PROJDATA\INITIAL\"
FileToOpen = Application _
.GetOpenFilename("Text Files (*.csv), *.csv") ' This grabs the whole file path
If TypeName(FileToOpen) = "Boolean" Then
Exit Sub
Else
Range("Info!m1").Value = FileToOpen 'This puts the file path into cell M1, then cell M2 chops it down.
connstring = "TEXT;" + FileToOpen
Sheets("Import").Select
With Selection.QueryTable
.Connection = connstring
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
btnFOMOCO
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,327
What error is displayed? Does the sheet have a query table? Verify this by putting

MsgBox Sheets("Import").QueryTables.Count

before the With line.
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
Its says 0 (zero) query tables. But none of my other spreadsheets have on either. I import the CSV file to populate customer documentation
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
It appears that somehow I deleted a named range called Q1248 on the import sheet that was associated with a connection. The range for that was A1:Q271 I tried to rename that range and got an error telling me that the name doesn't start with a letter or is used somewhere else.

Any Tips?
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
I fixed my name range on the import sheet, And its works. However I had to readjust any formula or reference to the import page, It moved them all to the right.

Thanks
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,751
Messages
5,833,487
Members
430,211
Latest member
Vandermeer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top