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
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