MACRO ANSI PARA UTF-8

cristianosevald

28-10-2014 19:29:57

Boa Tarde

Utilizo a seguinte macro para exportar um relatório de excel para txt

Sub Exportar()
Application.DisplayAlerts = False

template_file = ActiveWorkbook.FullName

fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:="C:\Users\Mepal\Desktop\PLANO DE CORTE PROJETOS" + _
VBA.Strings.Format(Now, "ddmmyyyy") + ".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

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub




PORÉM TENHO UM PROBLEMA QUE ELA ESTÁ SALVANDO NO FORMANTO ANSI E DEVE SER O CORRETO EM UTF-8

O QUE DEVO MODIFICAR NA MACRO?

Reinaldo

29-10-2014 11:04:33

Me parece que não há suporte no VBA, para salvar em UTF8 diretamente.
O "FileFormat=" pode utilizar os seguintes tipos(do Help VBA):

Código: Selecionar todos

XlFileFormat pode ser uma das seguintes constantes: 
xlCSV ;xlCSVMSDOS ;xlCurrentPlatformText ;xlDBF3 ;xlDIF ;xlExcel2FarEast ;xlExcel4 
xlAddIn ;xlCSVMac ;xlCSVWindows 
xlDBF2 ;xlDBF4 ;xlExcel2 ;xlExcel3 ;xlExcel4Workbook ;xlExcel5 ;xlExcel7 ;xlExcel9795 
xlHtml ;xlIntlAddIn ;xlIntlMacro ;xlSYLK ;xlTemplate ;
xlTextMac 
xlTextMSDOS 
xlTextPrinter 
xlTextWindows 
xlUnicodeText 
xlWebArchive ;xlWJ2WD1 ;xlWJ3;xlWJ3FJ3 ;xlWK1;xlWK1ALL ;xlWK1FMT ;xlWK3 
xlWK3FM3 ;xlWK4 ;xlWKS ;xlWorkbookNormal ;xlWorks2FarEast ;xlWQ1 ;xlXMLSpreadsheet 
São 4 tipos CSV e 4 tipos Text; e aparentemente nenhum deles é UTF8.
Em rapida pesquisa na net encontrei os seguintes tópicos, que podem auxilia-lo:
https://social.technet.microsoft.com/Fo ... -text-file
https://gist.github.com/JoBrad/1023484
http://techspread.wordpress.com/2012/12 ... macro-vba/
http://www.ozgrid.com/forum/showthread.php?t=164547
http://geek-mondain.blogspot.fr/2011/09 ... r-des.html