none
Code will not import XLS after importing a TXT file RRS feed

  • Question

  • I have a program that imports .XML, .XLS and .TXT files. When importing it populates TextBox's and then populates my workbook for later export. Whenever I import the .TXT files it stops me from being able to import any .XLS. I can still import XML but not XLS. The Text boxes flash but are empty.

    Here's the TXT code.

    vFileName = Application.GetOpenFilename

    If vFileName = False Then
    MsgBox "No Text Document Selected!"
    ' End
    Else

    Workbooks.OpenText fileName:=vFileName, _
    StartRow:=2, DataType:=xlDelimited, _
    TextQualifier:=xlTextQualifierNone, _
    ConsecutiveDelimiter:=False, Tab:=False, Semicolon:= _
    True, Comma:=False, Space:=False, Other:=False, _
    FieldInfo:=Array( _
    Array(1, 2), _
    Array(2, 9), _
    Array(3, 4), _
    Array(4, 4)), _
    DecimalSeparator:=",", ThousandsSeparator:="."

    ActiveSheet.Name = "vFileName"

    Worksheets("vFileName").Range("A91:A133").Copy
    TextBox1.SetFocus
    TextBox1.Paste

    Application.DisplayAlerts = False
    ActiveWorkbook.Close

    End If

    And here's the code to import XLS

    Dim thisWB As String

    Dim newWB As String

    thisWB = ActiveWorkbook.Name
    Application.DisplayAlerts = False

    On Error Resume Next

    Sheets("tempsheet").Delete

    On Error GoTo 0

    Dim customerBook As Workbook
    Dim filter As String
    Dim caption As String
    Dim customerFilename As String
    Dim customerWorkbook As Workbook
    Dim targetWorkbook As Workbook

    Set targetWorkbook = Application.ActiveWorkbook

    filter = "Text files (*.xls),*.xls"
    caption = "Please Select an input file "
    customerFilename = Application.GetOpenFilename(filter, , caption)
    If customerFilename = "False" Then GoTo Cancel

    Set customerWorkbook = Application.Workbooks.Open(customerFilename)

    Cells.Select
    Selection.Copy

    customerWorkbook.Close

    Sheets.Add
    ActiveSheet.Name = "tempsheet"
    Range("A1").Select
    ActiveSheet.Paste
    Thursday, August 22, 2013 3:09 PM