Esportazione dati su foglio xls predefinito

lunedì 08 giugno 2009 - 11.07

svil112 Profilo | Newbie

sto usando questo script per l'esportazione dei dati su un foglio xls, ma devo fare delle modifiche, cioe ho bisogno di esportare i dato su di un foglio gia predefinito, quindi devo esporatre i dati di un determinato giorno su questo foglio xls con campi gia predefiniti, ma non so come fare. Chi mi può dare un aiuto.
Private Sub cmdInvio_Click()

On Error Resume Next

Dim db As DAO.database
Dim rst As DAO.Recordset
Dim colonna As Integer
Dim numRecord As Long
Set db = CurrentDb

Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.workbook
Dim xlSheet As Excel.worksheet

If IsNull(txtData.Value) Then
MsgBox "Inserire una data"
Exit Sub
End If

Set rst = db.openrecordset("select nome,cognome,data from nome_tabella where data = #" & Format(txtData.Value, "mm/dd/yyyy") & "#")

numRecord = rst.RecordCount

If numRecord < 1 Then
MsgBox "Nessun record trovato", vbExclamation, "Nessun risultato"
Exit Sub
End If

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.workbooks.Add

xlApp.ScreenUpdating = False

Set xlSheet = xlWorkbook.Sheets(1)

For colonna = 0 To rst.Fields.Count - 1
xlSheet.Cells(1, colonna + 1).Value = rst.Fields(colonna).Name
Next

With xlSheet
.range("A2").CopyFromRecordset rst
End With

'Aggiungo colonna A
xlSheet.range("A:A").Insert Shift:=xlToLeft
xlSheet.range("a1").Value = "luogo"
'Aggiungo colonna D
xlSheet.range("D:D").Insert Shift:=xlToLeft
xlSheet.range("d1").Value = "parte"

'adatto la larghezza di tutte le colonne nel range A:E
xlSheet.Columns("A:E").EntireColumn.Autofit

xlApp.ScreenUpdating = True

Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing


End Sub
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5