Banco de dados SQL server,
esse e o script para exportação
Sub CommandButton2_Click()
'Nome do arquivo
Dia = Day(now)
Mes = Month(now)
Ano = Year(now)
Hora = Hour(now)
Minuto = Minute(now)
Segundo = Second(now)
Nome = “Trend Temperatura- " & Ano &”-" & Mes & “-” & Dia & " " & Hora & “h” & Minuto & “m” & Segundo & “s”
'Tipo do arquivo
Opcao = Application.ShowFilePicker(false, Nome, “csv”, 1, “Planilhas Excel (.csv)|.csv”)
if Opcao = true then
if Nome <> “” then
'Coleta informacoes da consulta
Set cs = Screen.Item(“E3Chart2”).Queries.Item(“Consulta2”).GetADORecordset()
tabela = cs.GetString(2, ,";", vbNewLine)
'As linhas abaixo montam o cabeçalho
cabecalho=""
n=cs.Fields.Count
for i=1 to n
cabecalho = cabecalho& cs.Fields(i-1).Name & “;”
next
Set aux2a = CreateObject(“Scripting.FileSystemObject”)
Set aux1a = aux2a.CreateTextFile(Nome, True)
aux1a.Close
'Criacao do corpo do arquivo CSV
Set aux = CreateObject(“Scripting.FileSystemObject”)
Set aux1 = aux.OpenTextFile(Nome,8)
aux1.WriteLine "Tabela: "& Screen.Item(“E3Chart2”).Queries.Item(“Consulta2”).table
aux1.WriteLine “”
aux1.WriteLine cabecalho
aux1.WriteLine tabela
aux1.Close
resp = MsgBox (“Deseja abrir o arquivo?”, vbYesNo + vbQuestion, “Abrir”)
if resp = 6 then 'YES
Application.ExecuteExternalApp Nome, “”, “”, 1
end if
end if
end if
End Sub