Newsgroup: it.comp.appl.access
Titolo: Trasferire in Excel

Ciao a tutti,
    volevo chiedere, č possibile aprire 1 file che ho appena creato?
CODICE PER TRASFERIRE I DATI IN EXCEL
 DoCmd.TransferSpreadsheet acExport, 0, "Report allievi per corso e
preadesione",
"C:\Documenti\CalendarioConsulting\AllieviPerCorsoEPreadesione.xls", , ""
ORA VOGLIO APRIRE IL FILE
    Set oApp = CreateObject("Excel.Application")
    Set f =
oApp.OpenTextFile("C:\Documenti\CalendarioConsulting\AllieviPerCorsoEPreades
ione.xls", , "")
    oApp.Visible = True
Non riesco a trovare nulla che mi possa essere utile, ho cercato nell'help
perň....
Forse non so dove cercare..
    Grazie

 wrote in message
9p1df3$gt$1...@news.flashnet.it...

Ti allego un esempio prelevato su un sito americano. Spero che possa
aiutarti.
 ---Posted by Dev Ashish---
 Modules: Transferring Records to Excel with Automation
    Excel's CopyFromRecordset method is probably the fastest way to copy
over the records via
Automation. It also provides a great deal of flexibility on where and how
the records are to be
copied. You can use a named range in an existing worksheet or specify
starting columns for the
records.
    Here are a couple of different ways to transfer a recordset over to
Excel. In order to use these
samples, set a reference to "Microsoft Excel 8.0 Object Library" under Tools
Menu/References
first.
     '************* Code Start *****************
     Sub sCopyFromRS()
     'Send records to the first
     'sheet in a new workbook
     '
     Dim rs As Recordset
     Dim intMaxCol As Integer
     Dim intMaxRow As Integer
     Dim objXL As Excel.Application
     Dim objWkb As Workbook
     Dim objSht As Worksheet
       Set rs = CurrentDb.OpenRecordset("Customers", _
                         dbOpenSnapshot)
       intMaxCol = rs.Fields.Count
       If rs.RecordCount > 0 Then
         rs.MoveLast:    rs.MoveFirst
         intMaxRow = rs.RecordCount
         Set objXL = New Excel.Application
         With objXL
           .Visible = True
           Set objWkb = .Workbooks.Add
           Set objSht = objWkb.Worksheets(1)
           With objSht
             .Range(.Cells(1, 1), .Cells(intMaxRow, _
                 intMaxCol)).CopyFromRecordset rs
           End With
         End With
       End If
     End Sub
     Sub sCopyRSExample()
     'Copy records to first 20000 rows
     'in an existing Excel Workbook and worksheet
     '
     Dim objXL As Excel.Application
     Dim objWkb As Excel.Workbook
     Dim objSht As Excel.Worksheet
     Dim db As Database
     Dim rs As Recordset
     Dim intLastCol As Integer
     Const conMAX_ROWS = 20000
     Const conSHT_NAME = "SomeSheet"
     Const conWKB_NAME = "J:\temp\book1.xls"
       Set db = CurrentDb
       Set objXL = New Excel.Application
       Set rs = db.OpenRecordset("Customers", dbOpenSnapshot)
       With objXL
         .Visible = True
         Set objWkb = .Workbooks.Open(conWKB_NAME)
         On Error Resume Next
         Set objSht = objWkb.Worksheets(conSHT_NAME)
         If Not Err.Number = 0 Then
           Set objSht = objWkb.Worksheets.Add
           objSht.Name = conSHT_NAME
         End If
         Err.Clear
         On Error GoTo 0
         intLastCol = objSht.UsedRange.Columns.Count
         With objSht
           .Range(.Cells(1, 1), .Cells(conMAX_ROWS, _
               intLastCol)).ClearContents
           .Range(.Cells(1, 1), _
             .Cells(1, rs.Fields.Count)).Font.Bold = True
           .Range("A2").CopyFromRecordset rs
         End With
       End With
       Set objSht = Nothing
       Set objWkb = Nothing
       Set objXL = Nothing
       Set rs = Nothing
       Set db = Nothing
     End Sub
     Sub sCopyRSToNamedRange()
     'Copy records to a named range
     'on an existing worksheet on a
     'workbook
     '
     Dim objXL As Excel.Application
     Dim objWkb As Excel.Workbook
     Dim objSht As Excel.Worksheet
     Dim db As Database
     Dim rs As Recordset
     Const conMAX_ROWS = 20000
     Const conSHT_NAME = "SomeSheet"
     Const conWKB_NAME = "c:\temp\book1.xls"
     Const conRANGE = "RangeForRS"
       Set db = CurrentDb
       Set objXL = New Excel.Application
       Set rs = db.OpenRecordset("Customers", dbOpenSnapshot)
       With objXL
         .Visible = True
         Set objWkb = .Workbooks.Open(conWKB_NAME)
         On Error Resume Next
         Set objSht = objWkb.Worksheets(conSHT_NAME)
         If Not Err.Number = 0 Then
           Set objSht = objWkb.Worksheets.Add
           objSht.Name = conSHT_NAME
         End If
         Err.Clear
         On Error GoTo 0
         objSht.Range(conRANGE).CopyFromRecordset rs
       End With
       Set objSht = Nothing
       Set objWkb = Nothing
       Set objXL = Nothing
       Set rs = Nothing
       Set db = Nothing
     End Sub
     '************* Code End *****************