Esempio di come puoi creare un modulo in Word che invia e
accoda dati su Excel utilizzando VBA su disco esterno
Ecco un esempio di come puoi creare un modulo in Word
Sub InviaEAccodaSuExcel()
Dim excelApp As Object
Dim excelWorkbook As Object
Dim excelSheet As Object
Dim rowNumber As Integer
' Crea un nuovo oggetto Excel.Application
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True ' Mostra Excel
' Apri il file Excel
Set excelWorkbook = excelApp.Workbooks.Open("F:\Dati.xlsx") '
' Seleziona il foglio di lavoro desiderato (o crea uno nuovo)
On Error Resume Next
Set excelSheet = excelWorkbook.Sheets("Dati") ' Cambia il nome del foglio di lavoro
se necessario
On Error GoTo 0
If excelSheet Is Nothing Then
' Se il foglio di lavoro non esiste, creane uno nuovo
Set excelSheet = excelWorkbook.Sheets.Add
excelSheet.Name = "Dati" ' Cambia il nome del foglio di lavoro se necessario
End If
' Trova la prima riga vuota nel foglio di lavoro
rowNumber = excelSheet.Cells(excelSheet.Rows.Count, 1).End(-4162).Row + 1 ' 4162
corrisponde a xlUp
' Scrivi i dati nel foglio di lavoro Excel
With excelSheet
.Cells(rowNumber, 1).Value = InputBox("Inserisci il nome:")
.Cells(rowNumber, 2).Value = InputBox("Inserisci il cognome:")
.Cells(rowNumber, 3).Value = InputBox("Inserisci il telefono:")
.Cells(rowNumber, 4).Value = InputBox("Inserisci l'email:")
.Cells(rowNumber, 5).Value = InputBox("Inserisci l'indirizzo:")
End With
' Salva e chiudi il file Excel
excelWorkbook.Save
excelWorkbook.Close
' Rilascia le risorse
Set excelSheet = Nothing
Set excelWorkbook = Nothing
Set excelApp = Nothing
End Sub