Results 1 to 5 of 5

Thread: Xls export to txt

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    72
    Rep Power
    12

    Xls export to txt

    Hi.
    Dear I have the following routine that exports to txt
    Code:
    Sub Exportar() 
        Application.DisplayAlerts = False 
    
        template_file = ActiveWorkbook.FullName 
    
        fileSaveName = Application.GetSaveAsFilename( _ 
                       InitialFileName:="C:\username" + _ 
                                        VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _ 
                       fileFilter:="Text Files (*.txt), *.txt") 
    
        If fileSaveName = False Then 
            Exit Sub 
        End If 
    
        'cria uma cópia da pasta de trabalho atual da planilha atual 
        Dim newBook As Workbook 
        Dim plan As Worksheet 
        Set newBook = Workbooks.Add 
    
        ThisWorkbook.ActiveSheet.Copy Before:=newBook.Sheets(1) 
    
        'exclui as demais planilhas 
        For Each plan In newBook.Sheets 
            If plan.Name <> ActiveSheet.Name Then 
                newBook.Worksheets(plan.Index).Delete 
            End If 
        Next 
    
        newBook.SaveAs Filename:= _ 
                              fileSaveName, FileFormat:=xlTextWindows, _ 
                              CreateBackup:=False 
    
        'fecha a pasta de trabalho gerada 
        newBook.Close SaveChanges:=True 
        Set newBook = Nothing 
    
        MsgBox "O arquivo foi exportado com sucesso! ", vbInformation, "Exportar arquivos" 
    
    End Sub
    The doubt is as follows, in order that the code is the same txt all exports to spreadsheet rows or 65536 rows! How can I adjust to the routine that exports only rows filled?

    Cross-Post
    Xls export to txt

    I appreciate the help

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Member
    Join Date
    Aug 2012
    Posts
    72
    Rep Power
    12
    I did not understand ....
    I need a code to get a file in xls, and transfome in a txt file

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    That's what the code does.

    Paste the code in a standard module and pass the parameters.

    Code:
    Sub ConvertRangeIntoTextFile(ByRef RangeToConvert, ByVal FileName As String, _
                                Optional FilePath As String, Optional Delim As String = vbTab)
    where pass the range,filename and optional filepath as well as the delimiter. That's all.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Member
    Join Date
    Aug 2012
    Posts
    72
    Rep Power
    12
    hI.
    in my testing is being created a file in XLS format

Similar Threads

  1. Export data from Excel to Access Table (ADO) using VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 02-24-2015, 07:53 PM
  2. 20$ Export from outlook to Excel
    By jamilm in forum Hire A Developer
    Replies: 22
    Last Post: 07-16-2013, 11:27 PM
  3. Export outlook emails to Excel code Error
    By jamilm in forum Outlook Help
    Replies: 2
    Last Post: 02-22-2013, 03:48 PM
  4. export all worksheets to separate csv files
    By rabidfly in forum Excel Help
    Replies: 4
    Last Post: 11-18-2012, 02:11 PM
  5. Macro to export sheet as CSV
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 07-25-2012, 08:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •