Newsgroup: it.comp.lang.visual-basic
Titolo: da VB scrivere in un file di Excel

Ciao
Ho un MDB e vorrei esportare i suoi dati in un file XLS. Come posso fare
con il VB?
(mi bastano poche dritte, tanto per partire...)
-- 
Ciao da MioMao!
-----------------------------------------------------------
Visita la mia CasaPagina!
http://www.digibank.it/miomao
-----------------------------------------------------------
If vorresbi reply me privatamente,
dovesbi remove la parola FINTO dallo
mio indirizzo Email - Chiaro, no?!?

Ciao da MioMao!
Con questa funzione esporti una grid in un foglio di excel, ti basta
visualizzare l'mdb in una grid oppure apportare qualche lieve modifica.
Ciao
Luca
----------------------------------------------------------------------------
--------------------------------------
    Public Function SaveExcelWorksheet(MSFlexGrid1 As Object, argProjectName
As String, _
        argWorkbookFile As String, argErrorMessage As String) As Integer
        Dim numbercolumns As Long
        Dim NumberRows As Long
        Dim FieldData() As String
        Dim XL As Object
        Dim wrkRow As Long
        Dim wrkColumn As Integer
        Dim wrkFlag As Long
        Dim wrkStringLength As Integer
        Dim ExcelWork() As Variant
        Dim ExcelRightJustify() As Integer
        Dim ExcelColumnWidth() As Single
        Dim wrkString As String
        Dim wrkRowOut As Integer
        Dim x As Integer
        Dim Y As Integer
    '  Load Field Names
        numbercolumns = MSFlexGrid1.Cols - 1
        ReDim FIELDNAMES(1 To numbercolumns)
        NumberRows = MSFlexGrid1.Rows - 1
        ReDim FieldData(1 To NumberRows, 1 To numbercolumns)
        MSFlexGrid1.Redraw = False
        For x = 0 To NumberRows - 1
            For Y = 1 To numbercolumns
                    MSFlexGrid1.Row = x
                    MSFlexGrid1.col = Y
                    FieldData(x + 1, Y) = MSFlexGrid1.Text
            Next
        Next
        MSFlexGrid1.Redraw = True
        SaveExcelWorksheet = False
        ReDim ExcelRightJustify(1 To numbercolumns)
        ReDim ExcelColumnWidth(1 To numbercolumns)
        ReDim ExcelWork(1 To numbercolumns)
    '  Open the Excel Worksheet
        Set XL = CreateObject("Excel.Sheet")
    '  Write Project Details
        With XL.Application
            XL.Application.Visible = True
            '  Set the Size of the Work Array
            ReDim ExcelWork(1 To NumberRows, 1 To numbercolumns)
            '  Set the Number of Rows Output
             wrkRowOut = 0
            '  Write Data to Excel Worksheet
            '  Go Through Each Row of Data
              For wrkRow = 1 To NumberRows
               '  Increase the Number of Rows Exported
                  wrkRowOut = wrkRowOut + 1
                '  Go Through Each Column of Data
                For wrkColumn = 1 To numbercolumns
                    wrkString = FieldData(wrkRow, wrkColumn)
                    ExcelWork(wrkRowOut, wrkColumn) = wrkString
                    If (ExcelRightJustify(wrkColumn) = True) Then
                        If (wrkString <> "") Then
                            wrkFlag = IsNumeric(wrkString)
                            ExcelRightJustify(wrkColumn) = wrkFlag
                         End If
                End If
    '
    '  Test whether the Column is Wide Enough
                wrkStringLength = Len(wrkString)
                If (wrkStringLength > ExcelColumnWidth(wrkColumn)) Then
                    ExcelColumnWidth(wrkColumn) = CSng(wrkStringLength) +
0.11
                    XL.Application.Columns(wrkColumn).ColumnWidth =
ExcelColumnWidth(wrkColumn)
                End If
            Next wrkColumn
    '  Save the Data in the Worksheet
                With XL.Application
                    .Range(.Cells(wrkRow - wrkRowOut + 11, 1), _
                        .Cells(wrkRow, numbercolumns)).value = ExcelWork
                End With
                wrkRowOut = 0
          '  End If
    '
    '  Get Next Row of Data
        Next wrkRow
    '
    '  Put any unstored Rows into the Worksheet
        With XL.Application
            If (wrkRowOut > 0) Then
                .Range(.Cells(NumberRows - wrkRowOut + 11, 1), _
                   .Cells(NumberRows + 10, numbercolumns)).value = ExcelWork
            End If
    '
        End With
    '
    '  Save the Worksheet
        XL.SaveAs argWorkbookFile
    '
    '  Close Excel Application
        XL.Application.Quit
        Set XL = Nothing
        SaveExcelWorksheet = True
        Exit Function
        End With
    End Function

 (mi bastano poche dritte, tanto per partire...)
Guarda nell'esempio VisData di VB.
Ciao Bruno





Ti ringrazio molto, era proprio cio' che cercavo :-)- 


...

..e tre! :-)
Giuro che l'ho guardato!!! :-)))))
