Copy excel sheet to text file

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hello,
I currently use the below code to find and select a .txt file. The code then formats that text file from comma seperated and copies this information to an excel spreadsheet (which is seperated by cells instead of commas).

Code:
Dim Filter As String, Title As String, Msg As String
    Dim FilterIndex As Integer
    Dim FilenameClient As Variant
    Dim Wkb2 As Workbook
  
    Const PTH = "S:\FMS\FMS - Foreign Exchange\Global Link - Finished Deals\PrimeCo Upload\"
        Dim strFile As String
        strFile = Dir(PTH & "*.*")
        If Len(strFile) > 0 Then
            Do
                Kill PTH & strFile
                strFile = Dir
                Loop While Len(strFile) > 0
                'MsgBox "Current File Deleted"
                'Else
            'MsgBox "No File Found"
        End If
     ' File filters
    Filter = "Text Files (Finish_mel.ncssell*.txt),[Finish_mel.ncssell*.txt],"
     '"All Files (*.*),*.*"
     '"Excel Files (*.xls),*.xls," & _
     'Default filter *.*
    
    FilterIndex = 1
    
    'Set Dialog Caption
    Title = "Select Mel Side"
    
      'Select Start Drive & Path
      ChDrive ("S")
      ChDir ("S:\FMS\FMS - Foreign Exchange\Global Link - Finished Deals")
      
      With Application
      
       ' Set File Name Array to selected Files (allow multiple) False = Single
        FilenameClient = .GetOpenFileName(Filter, FilterIndex, Title, , False)
              
        Workbooks.OpenText FileName:=FilenameClient _
        , Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
        Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 4), Array(13, 1), Array(14, 1), Array(15 _
        , 4), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), _
        Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1)), TrailingMinusNumbers:=True
        Columns("L:L").ColumnWidth = 10.29
                             
        Set Wkb2 = ActiveWorkbook
        Wkb2.ActiveSheet.UsedRange.Copy Workbooks("PrimeCo.xlsm").Worksheets("Mel").Range("A1")
                       
        YesNo = MsgBox("Is this the Correct MEL Side File?", vbYesNo + vbQuestion, "Click on Yes or No")
        Select Case YesNo
          
          Case vbYes
            Windows("PrimeCo.xlsm").Activate
            'Sheets("PrimeCo Home").Select
          
          Case vbNo
            Windows("PrimeCo.xlsm").Activate
            Sheets("Mel").Cells.Clear
            Windows("PrimeCo.xlsm").Activate
            Sheets("PrimeCo Home").Select
            
        End Select
        
        End With
        Wkb2.Close savechanges:=False
        
        'End Select
    End Sub

What I would like to do is to select an excel spread sheet, convert the information (which is seperated by cells) and copy this information into a text file with the same format as the text files that were originally converted above (i.e. comma seperated).

Any help would be appreciated.
Thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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