In particolare la macro, salva alcuni dati (celle) in un file esterno. Lancio la macro che fa il suo dovere, apre il file di destinazione e copia le celle al loro posto, però a questo punto si blocca tutto. ho la sensazione come se ci fosse qualcosa che va in loop, ma non riesco a capire cosa.
Allego la macro, Uso MacOs 13.1
Grazie
Codice: Seleziona tutto
Sub SalvaInContabilita
Dim DocName as object, DocUlr as string, dummy(), range as object, sVar as Integer
Doc = ThisComponent
sheet = Doc.currentcontroller.getActiveSheet() 'Seleziona il foglio visualizzato
NomeFoglioArchivio = sheet.getCellRangeByName("A3").String ' il nome del foglio di destinazione
sVar = MsgBox( "Vuoi continuare con il salvataggio [ " & NomeFoglioArchivio &  " " & sheet.getCellRangeByName("A4").string & " ]  nel file di contabilità?",   MB_YESNO )
If sVar = IDYES  Then
sFileName ="/Users/utente/Documents/Contabilità/2023/23-Riepilogo-Contabilità.ods"  ' file destinazione NAS
'sFileName ="/Users/utente/Desktop/Contabilità-2020.ods" 'file destinazione test
DocUrl = ConvertToURL(sFileName)
DocName = StarDesktop.loadComponentFromURL (DocUrl, "_blank",0, Dummy() )
'Preventivo = DocName.Sheets.getbyname("Preventivi") ' il nome del foglio di destinazione
If NomeFoglioArchivio = "Preventivo n°" Then
Archivio = DocName.Sheets.getbyname("Ultima Preventivo")
Else
Archivio = DocName.Sheets.getbyname("Ultima Fattura")
End if
REM ---Loop che controlla celle di colonna A ...
'incrementando il valore della variabile “Riga” fino a trovare il valore della prima riga libera
Riga = 1
Do while Archivio.getCellByPosition(0,Riga).string <> ""
Riga = Riga + 1
Loop
Archivio.getCellByPosition(0,Riga).String = Sheet.getCellRangeByName("E4").String 		'Riferimento
Archivio.getCellByPosition(2,Riga).String = Sheet.getCellRangeByName("F3").String 			'Cliente
Archivio.getCellByPosition(3,Riga).String = Sheet.getCellRangeByName("F4").String			'Nome
Archivio.getCellByPosition(15,Riga).String = Sheet.getCellRangeByName("A4").String		'N°
Archivio.getCellByPosition(5,Riga).Formula = Sheet.getCellRangeByName("C4").Formula	'Data
Archivio.getCellByPosition(6,Riga).String = Sheet.getCellRangeByName("A1").String			'Descrizione
Archivio.getCellByPosition(7,Riga).Value = Sheet.getCellRangeByName("A8").Value		'Imponibile
Archivio.getCellByPosition(8,Riga).Value = Sheet.getCellRangeByName("C8").Value		'IVA
Archivio.getCellByPosition(9,Riga).Value = Sheet.getCellRangeByName("D8").Value		'Totale
DocName.store
DocName.Close(true)
MsgBox (" Archiviazione  [ " & NomeFoglioArchivio & " " & sheet.getCellRangeByName("A4").string & " ]  EFFETTUATA con successo nel file di contabilità.")
Else
MsgBox (" Archiviazione  [ " & NomeFoglioArchivio & " " & sheet.getCellRangeByName("A4").string & " ]  NON effettuata nel file di contabilità.")
End If
End Sub


