marreco
01-21-2015, 03:48 AM
Hi.
I need use this code, but export specific range("A1:C100")
Sub Export_to_txt_file() Application.DisplayAlerts = False
template_file = ActiveWorkbook.FullName
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:="C:\" + "saida.txt", _
fileFilter:="Text Files (*.txt), *.txt")
If fileSaveName = False Then
Exit Sub
End If
Dim newBook As Workbook
Dim plan As Worksheet
Set newBook = Workbooks.Add
'I need only export range("A1:C100"), do not full sheet, how do it?
ThisWorkbook.ActiveSheet.Copy Before:=newBook.Sheets(1)
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
newBook.Close SaveChanges:=True
Set newBook = Nothing
MsgBox "O arquivo foi exportado com sucesso! ", vbInformation, "Exportar arquivos"
End Sub
Thank you!!
I need use this code, but export specific range("A1:C100")
Sub Export_to_txt_file() Application.DisplayAlerts = False
template_file = ActiveWorkbook.FullName
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:="C:\" + "saida.txt", _
fileFilter:="Text Files (*.txt), *.txt")
If fileSaveName = False Then
Exit Sub
End If
Dim newBook As Workbook
Dim plan As Worksheet
Set newBook = Workbooks.Add
'I need only export range("A1:C100"), do not full sheet, how do it?
ThisWorkbook.ActiveSheet.Copy Before:=newBook.Sheets(1)
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
newBook.Close SaveChanges:=True
Set newBook = Nothing
MsgBox "O arquivo foi exportado com sucesso! ", vbInformation, "Exportar arquivos"
End Sub
Thank you!!