codice:Option Explicit Dim xlApp(1 To 2) As Excel.Application Dim xlWkB As Excel.Workbook Dim LastCellSorgente As String Dim LastCellDest As String Dim RIGA As String Dim a Private Sub cmdAccoda_Click() If txtFileSorgente = "" Then MsgBox "Indicare il file sorgente", vbExclamation, Me.Caption txtFileSorgente.SetFocus Exit Sub End If If txtFileDestinazione = "" Then MsgBox "Indicare il file di destinazione", vbExclamation, Me.Caption txtFileDestinazione.SetFocus Exit Sub End If Me.MousePointer = 11 'File Sorgente Set xlApp(1) = New Excel.Application xlApp(1).DisplayAlerts = False 'File Destinazione Set xlApp(2) = New Excel.Application Set xlWkB = xlApp(2).Workbooks.Open(txtFileDestinazione) xlApp(1).Workbooks.Open (txtFileSorgente) LastCellSorgente = xlApp(1).ActiveCell.SpecialCells(xlCellTypeLastCell).Address LastCellSorgente = Replace(LastCellSorgente, "$", "") LastCellDest = xlApp(2).ActiveCell.SpecialCells(xlCellTypeLastCell).Address RIGA = Mid(LastCellDest, (InStrRev(LastCellDest, "$") + 1)) xlApp(1).Range("A1:" & LastCellSorgente).Copy If RIGA = 1 Then xlApp(2).Range("A" & RIGA).PasteSpecial xlPasteValues Else xlApp(2).Range("A" & (RIGA + 1)).PasteSpecial xlPasteValues End If xlApp(1).Quit xlApp(2).Range("A1").Activate xlWkB.Close (True) xlApp(2).Quit Set xlApp(1) = Nothing Set xlApp(2) = Nothing Me.MousePointer = 0 MsgBox "Operazione terminata", , Me.Caption End Sub Private Sub cmdEsci_Click() End End Sub Private Sub cmdFileSorgente_Click() cdApriFile.ShowOpen txtFileSorgente = cdApriFile.FileName End Sub Private Sub Command1_Click() cdApriFile.ShowOpen txtFileDestinazione = cdApriFile.FileName End Sub

Rispondi quotando