Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
ciao Francesco,
testa questa routine :
Private Sub test()
On Error GoTo errorHandler
Dim lune As String
Dim saba As String
Dim Rng As Object ' Excel.Range
Dim oBook As Object ' Excel.WorkBook
Dim oSheet As Object ' Excel.WorkSheet
Dim oExcel As Object ' Excel.Application
Dim nomeFileSalvato As String
Dim lngLastRow As Long
Const strClass As String = "Excel.Application"
'lune = Year(txtDataLun) & "." & Month(txtDataLun) & "." & Day(txtDataLun)
'saba = Year(txtDataSab) & "." & Month(txtDataSab) & "." & Day(txtDataSab)
' prova a sostituire le istruzioni di cui sopra come segue :
'lune =format$(txtDataLun,"yyyy.m.d")
'saba=format$(txtDataSab,"yyyy.m.d")
nomeFileSalvato = "c:\pianificazione\settimana_" & lune & "_" & saba & ".xlsx"
On Error Resume Next
Set oExcel = GetObject(, strClass)
If Err.Number = 429 Then
Set oExcel = CreateObject(strClass)
End If
On Error GoTo 0
Set oBook = oExcel.Workbooks.Open(nomeFileSalvato)
For Each oSheet In oBook.sheets
On Error Resume Next
lngLastRow = LastRow(oSheet)
With oSheet
Set Rng = .Range("G2:AA" & lngLastRow)
Rng.FormatConditions.Delete
End With
On Error GoTo 0
Dim cond1 As Object, cond2 As Object, cond3 As Object
Dim cond4 As Object, cond5 As Object, cond6 As Object
Dim cond7 As Object, cond8 As Object, cond9 As Object
Dim cond10 As Object, cond11 As Object, cond12 As Object
Dim cond13 As Object, cond14 As Object, cond15 As Object
Dim cond16 As Object, cond17 As Object, cond18 As Object
With Rng.FormatConditions
Set cond1 = .Add(1, 3, "A")
Set cond2 = .Add(1, 3, "X")
Set cond3 = .Add(1, 3, "2")
Set cond4 = .Add(1, 3, "R")
Set cond5 = .Add(1, 3, "S")
Set cond6 = .Add(1, 3, "T")
Set cond7 = .Add(1, 3, "O")
Set cond8 = .Add(1, 3, "-")
Set cond9 = .Add(1, 3, "M")
Set cond10 = .Add(1, 3, "C")
Set cond11 = .Add(1, 3, "F")
Set cond12 = .Add(1, 3, "MR")
Set cond13 = .Add(1, 3, "SS")
Set cond14 = .Add(1, 3, "TP")
Set cond15 = .Add(1, 3, "PT")
Set cond16 = .Add(1, 3, "RO")
Set cond17 = .Add(1, 3, "FR")
Set cond18 = .Add(1, 3, "SR")
End With
With cond1
.Interior.Color = 65535 ' giallo
.Font.Color = 0 ' nero
End With
With cond2
.Interior.Color = 255 ' Rosso
.Font.Color = 16777215 ' bianco
End With
With cond3
.Interior.Color = 15631086 ' viola
.Font.Color = 0 ' nero
End With
With cond4
.Interior.Color = 8388352 ' verde
.Font.Color = 0 ' nero
End With
With cond5
.Interior.Color = 5219839 ' marrone chiaro
.Font.Color = 0 ' nero
End With
With cond6
.Interior.Color = 9445584 ' viola
.Font.Color = 16777215 ' bianco
End With
With cond7
.Interior.Color = 2841227 ' marrone scuro
.Font.Color = 16777215 ' bianco
End With
With cond8
.Interior.Color = 15453831 ' azzurro
.Font.Color = 0 ' nero
End With
With cond9
.Interior.Color = 0 ' nero
.Font.Color = 16777215 ' bianco
End With
With cond10
.Interior.Color = &H808080 ' grigio
.Font.Color = &H0 ' nero
End With
With cond11
.Interior.Color = 4557568 ' verde acceso
.Font.Color = 0 ' nero
End With
With cond12
.Interior.Color = 7794176 ' verdino
.Font.Color = 16777215 ' bianco
End With
With cond13
.Interior.Color = 14772544 ' Navy
.Font.Color = 16777215 ' bianco
End With
With cond14
.Interior.Color = 13224397 ' silver
.Font.Color = 9445584 ' purple
End With
With cond15
.Interior.Color = 16448255 ' grigio
.Font.Color = 9445584 ' purple
End With
With cond16
.Interior.Color = 4356590 ' marron
.Font.Color = 9445584 ' purple
End With
With cond17
.Interior.Color = 3706510 ' Oliva
.Font.Color = 9445584 ' purple
End With
With cond18
.Interior.Color = 65280 ' giallo/verde
.Font.Color = 9445584 ' purple
End With
Next
With oExcel
.displayAlerts = False
oBook.Close SaveChanges:=True _
, FileName:=nomeFileSalvato
.displayAlerts = True
End With
VBA.MsgBox prompt:="Ho finito.", _
buttons:=vbInformation + vbOKOnly, _
title:="Info"
exitErrorHandler:
Set cond1 = Nothing
Set cond2 = Nothing
Set cond3 = Nothing
Set cond4 = Nothing
Set cond5 = Nothing
Set cond6 = Nothing
Set cond7 = Nothing
Set cond8 = Nothing
Set cond9 = Nothing
Set cond10 = Nothing
Set cond11 = Nothing
Set cond12 = Nothing
Set cond13 = Nothing
Set cond14 = Nothing
Set cond15 = Nothing
Set cond16 = Nothing
Set cond17 = Nothing
Set cond18 = Nothing
Set oSheet = Nothing
Set oBook = Nothing
oExcel.Quit
Set oExcel = Nothing
Exit Sub
errorHandler:
With Err
MsgBox "ERR#" & CStr(.Number) _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical
End With
Resume exitErrorHandler
End Sub
ciao, Sandro.