[Risolto]2 macro in contenuto modificato

Creare una macro - Scrivere uno script - Usare le API
Rispondi
epico
Messaggi: 58
Iscritto il: mercoledì 4 giugno 2014, 11:53

[Risolto]2 macro in contenuto modificato

Messaggio da epico »

Salve,
nel file che stò utilizzando c'è una macro in Eventi foglio > contenuto modificato che inserisce la data in vari range semplicemente scrivendo solo il giorno http://forum.openoffice.org/it/forum/vi ... =26&t=7576

Codice: Seleziona tutto

Sub DataB(Target) 
 If NOT Target.supportsService("com.sun.star.sheet.SheetCell") then exit sub
   sh = Target.getSpreadsheet()
   Rngs = ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
   Rngs.addRangeAddress(sh.getCellRangeByName("B4:B45").getRangeAddress() ,False )
   Rngs.addRangeAddress(sh.getCellRangeByName("B57:B98").getRangeAddress() ,False )
   Rngs.addRangeAddress(sh.getCellRangeByName("B110:B151").getRangeAddress() ,False )

   range2 = Rngs.queryintersection(Target.rangeaddress())
   If range2.RangeAddressesAsString = "" Then  Exit Sub
      Mesi = Array("GEN", "FEB", "MAR", "APR", "MAG", "GIU", "LUG", "AGO", "SET", "OTT", "NOV", "DIC")
      gg = Target.Value
      For i= 0 To Ubound(Mesi)
        If sh.name = Mesi(i) Then mese = i + 1 :  exit For
      Next i 
      Anno = sh.getcellrangebyname("J1").value
      svc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
      Dim  param(1) as variant
      param(0) = CDbl(DateSerial(Anno, mese, 1))
      param(1) = 0 
      dataFin = svc.CallFunction("com.sun.star.sheet.addin.Analysis.getEomonth",param())
      If Target.Value >= 1 And Target.Value <= Day(dataFin) Then 
         Target.Value = DateSerial(Anno, mese, gg)
     
      End If
      
End Sub
Adesso vorrei poter anche nascondere vari range di righe al variare di A1 con quest'altra macro
1 visualizza tutte le righe
2 nasconde righe A2:A53
3 nasconde righe A2:A106

Ho provato a inserirla nel foglio3 e funziona

Codice: Seleziona tutto

Sub NascondiMostra
Sheet = ThisComponent.CurrentController.ActiveSheet

    if Sheet.getCellRangeByName("A1").value = 1 then
    Sheet.getCellRangeByName("A2:A106").Rows().IsVisible = True

    elseif Sheet.getCellRangeByName("A1").value = 2 then
    Sheet.getCellRangeByName("A2:A53").Rows().IsVisible = False
    Sheet.getCellRangeByName("A54:A106").Rows().IsVisible = True


    elseif Sheet.getCellRangeByName("A1").value = 3 then
    Sheet.getCellRangeByName("A2:A106").Rows().IsVisible = False

  end if
End sub
ma non sono in capace di farla funzionare assieme all'altra macro.

Ho crearne una unica, ho qualsiasi altro metodo ...??

Grazie
Allegati
prova-01.ods
(33.6 KiB) Scaricato 157 volte
Ultima modifica di epico il mercoledì 29 luglio 2020, 23:58, modificato 1 volta in totale.
OpenOffice 4.1 su Win10
patel
Volontario attivo
Volontario attivo
Messaggi: 4020
Iscritto il: venerdì 30 aprile 2010, 8:04
Località: Livorno

Re: 2 macro in contenuto modificato

Messaggio da patel »

fai queste modifiche

Codice: Seleziona tutto

Sub DataB(Target) 
 If NOT Target.supportsService("com.sun.star.sheet.SheetCell") then exit sub
   sh = Target.getSpreadsheet()
   oCellT() = Split(Target.AbsoluteName, ".")
   oCellTarget = oCellT(1)
   If oCellTarget = "$A$1" Then
     NascondiMostra
     exit sub
   end if
'segue il resto della tua macro
-------------------
Libre Office 7.5.3.2 su Windows 11
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta
epico
Messaggi: 58
Iscritto il: mercoledì 4 giugno 2014, 11:53

Re: 2 macro in contenuto modificato

Messaggio da epico »

:super: Grazie

Se può essere utile

Codice: Seleziona tutto

Sub DataB(Target) 
 If NOT Target.supportsService("com.sun.star.sheet.SheetCell") then exit sub
   sh = Target.getSpreadsheet()
   
   
    oCellT() = Split(Target.AbsoluteName, ".")
   oCellTarget = oCellT(1)
   If oCellTarget = "$A$1" Then
     NascondiMostra
     exit sub
   end if
      
   
   Rngs = ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
   Rngs.addRangeAddress(sh.getCellRangeByName("B4:B45").getRangeAddress() ,False )
   Rngs.addRangeAddress(sh.getCellRangeByName("B57:B98").getRangeAddress() ,False )
   Rngs.addRangeAddress(sh.getCellRangeByName("B110:B151").getRangeAddress() ,False )

   range2 = Rngs.queryintersection(Target.rangeaddress())
   If range2.RangeAddressesAsString = "" Then  Exit Sub
      Mesi = Array("GEN", "FEB", "MAR", "APR", "MAG", "GIU", "LUG", "AGO", "SET", "OTT", "NOV", "DIC")
      gg = Target.Value
      For i= 0 To Ubound(Mesi)
        If sh.name = Mesi(i) Then mese = i + 1 :  exit For
      Next i 
      Anno = sh.getcellrangebyname("J1").value
      svc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
      Dim  param(1) as variant
      param(0) = CDbl(DateSerial(Anno, mese, 1))
      param(1) = 0 
      dataFin = svc.CallFunction("com.sun.star.sheet.addin.Analysis.getEomonth",param())
      If Target.Value >= 1 And Target.Value <= Day(dataFin) Then 
         Target.Value = DateSerial(Anno, mese, gg)
     
      End If
      
End Sub


Sub NascondiMostra
Sheet = ThisComponent.CurrentController.ActiveSheet

    if Sheet.getCellRangeByName("A1").value = 1 then
    Sheet.getCellRangeByName("A2:A106").Rows().IsVisible = True

    elseif Sheet.getCellRangeByName("A1").value = 2 then
    Sheet.getCellRangeByName("A2:A53").Rows().IsVisible = False
    Sheet.getCellRangeByName("A54:A106").Rows().IsVisible = True

    elseif Sheet.getCellRangeByName("A1").value = 3 then
    Sheet.getCellRangeByName("A2:A106").Rows().IsVisible = False

  end if
End sub
OpenOffice 4.1 su Win10
Rispondi