View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Die_Another_Day Die_Another_Day is offline
external usenet poster
 
Posts: 644
Default Import Data Macro

Try it like this. I've never used the QueryTables before so that might
be where the wrong syntax is. Let me know what line you get the error
on, if you still get the error.

Charles

Dim File1 As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Title = "Please Select Text File to Import"
If .Show Then
File1 = .SelectedItems(1)
MsgBox File1
Else
MsgBox "User Clicked Cancel"
End If
End With

With ActiveSheet.QueryTables.Add(Connection:=File1 _
Destination:=Range("A2"))
.Name = "subcount"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub