Xls export to txt

marreco

Well-known Member
Joined
Jan 1, 2011
Messages
609
Office Version
  1. 2010
Platform
  1. Windows
Hi
Dear I have the following routine that exports to txt
Code:
[COLOR=#000000][FONT=Verdana]Sub Exportar() [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Application.DisplayAlerts = False [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    template_file = ActiveWorkbook.FullName [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    fileSaveName = Application.GetSaveAsFilename( _ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]                   InitialFileName:="C:\username" + _ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]                                    VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]                   fileFilter:="Text Files (*.txt), *.txt") [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    If fileSaveName = False Then [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]        Exit Sub [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    End If [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    'cria uma cópia da pasta de trabalho atual da planilha atual [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Dim newBook As Workbook [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Dim plan As Worksheet [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Set newBook = Workbooks.Add [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    ThisWorkbook.ActiveSheet.Copy Before:=newBook.Sheets(1) [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    'exclui as demais planilhas [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    For Each plan In newBook.Sheets [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]        If plan.Name <> ActiveSheet.Name Then [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]            newBook.Worksheets(plan.Index).Delete [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]        End If [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Next [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    newBook.SaveAs Filename:= _ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]                          fileSaveName, FileFormat:=xlTextWindows, _ [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]                          CreateBackup:=False [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    'fecha a pasta de trabalho gerada [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    newBook.Close SaveChanges:=True [/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]    Set newBook = Nothing [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]    MsgBox "O arquivo foi exportado com sucesso! ", vbInformation, "Exportar arquivos" [/FONT][/COLOR]

[COLOR=#000000][FONT=Verdana]End Sub[/FONT][/COLOR]
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?


I appreciate the help
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi!

Try to fit this:
Code:
ActiveSheet.SpecialCells(xlCellTypeConstants, 23).Select
somewhere in your code.
 
Upvote 0
Hi.

I'm try

Code:
[COLOR=#000000][FONT=Verdana]Sub Exportar()[/FONT][/COLOR][COLOR=#000000][FONT=Verdana]    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)
    ActiveSheet.SpecialCells(xlCellTypeConstants, 23).Select '<--Linha acrescentada
    '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


[/FONT][/COLOR]

Displayed the following message: Object does not support this property or method

Thanks for the help!
 
Upvote 0
May be you should give a cell range like:
Code:
ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, 23).Select
Else, I don't know :(
 
Upvote 0
Ahh! I didn't get your code really well but it first creates a new sheet and then saves. It is maybe because your new sheet is empty. I have no more idea, sorry...
 
Upvote 0
hi, Flashbond, thanks for the willingness to help.
let's see if anyone else has any idea how to help me.


Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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