Test vba

chich

XLDnaute Occasionnel
Bonjour la communauté
je souhait savoir comment faire un test si la feuille ("GESTION DIVERS") est visible dans ma macro
Sub PREV( )
Dim c As Range
Application.ScreenUpdating = False
With Sheets("GESTION DIVERS")
For Each c In .Range(.[APl10], .[APl65536].End(xlUp))
If c.Value < DateSerial(Year(Date), Month(Date) + 3, Day(Date)) Then
If txt = "" Then txt = "Attention préavis fin de validitée(s):" & vbCrLf
txt = txt & c.Offset(, -2) & " " & c.Offset(, -1) & vbCrLf
End If
Next c
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
End Sub
merci
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonjour Chich, bonjour le forum,

Essaie comme ça :

VB:
Sub PREV()
Dim c As Range
Application.ScreenUpdating = False

With Sheets("GESTION DIVERS")
  If .Visible = -1 Then '-1 si visible, 0 si masquée, 2 si très masquée (VeryHidden)
  For Each c In .Range(.[APl10], .[APl65536].End(xlUp))
  If c.Value < DateSerial(Year(Date), Month(Date) + 3, Day(Date)) Then
  If txt = "" Then txt = "Attention préavis fin de validitée(s):" & vbCrLf
  txt = txt & c.Offset(, -2) & " " & c.Offset(, -1) & vbCrLf
  End If
  Next c
  If txt <> "" Then MsgBox txt
  End If
End With
Application.ScreenUpdating = True
End Sub
 

chich

XLDnaute Occasionnel
Bonjour Chich, bonjour le forum,

Essaie comme ça :

VB:
Sub PREV()
Dim c As Range
Application.ScreenUpdating = False

With Sheets("GESTION DIVERS")
  If .Visible = -1 Then '-1 si visible, 0 si masquée, 2 si très masquée (VeryHidden)
  For Each c In .Range(.[APl10], .[APl65536].End(xlUp))
  If c.Value < DateSerial(Year(Date), Month(Date) + 3, Day(Date)) Then
  If txt = "" Then txt = "Attention préavis fin de validitée(s):" & vbCrLf
  txt = txt & c.Offset(, -2) & " " & c.Offset(, -1) & vbCrLf
  End If
  Next c
  If txt <> "" Then MsgBox txt
  End If
End With
Application.ScreenUpdating = True
End Sub
RE
Merci pour ton aide je voudrais que la macro ne s’exécute que si la feuille est visible
 

chich

XLDnaute Occasionnel
Re,

Ben Heu !... C'est que je t'ai proposé il me semble avec la conditionnelle
If .Visible = -1... End If. Si t'avais pris la peine de tester t'aurais vu !...
RE
Je te confirme j' ai plusieurs test la macro s'exécute même si la feuille et cacher j'appel (prev) dans une autre
macro d' attribution de droit d'accès au feuilles de mon classeur
Sub Workbook_Open()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "ACCES" Then ws.Visible = xlSheetVeryHidden
Next ws
UserForm1.Show
Call PREV
Application.ScreenUpdating = True
End Sub
Sub PREV()
Dim c As Range
Application.ScreenUpdating = False
With Sheets("GESTION DIVERS")
If .Visible = -1 Then
End If
For Each c In .Range(.[APl10], .[APl65536].End(xlUp))
If c.Value < DateSerial(Year(Date), Month(Date) + 3, Day(Date)) Then
If txt = "" Then txt = "Attention préavis fin de validitée(s):" & vbCrLf
txt = txt & c.Offset(, -2) & " " & c.Offset(, -1) & vbCrLf
End If
Next c
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
End Sub
Option Explicit

Function VerifMDP(Utilisateur As String, MdP As String) As Boolean
Dim rngTrouve As Range
VerifMDP = False

With Sheets("parametrage")
Set rngTrouve = .Columns(1).Cells.Find(Utilisateur, lookat:=xlWhole)
If rngTrouve Is Nothing Then
VerifMDP = False
Else
If rngTrouve.Offset(0, 1) <> MdP Then
VerifMDP = False
Else
VerifMDP = True
End If
End If
End With
End Function
Sub AfficheFeuilles(Utilisateur As String)
Dim Col As Byte, i As Byte, Lig As Integer

With Sheets("parametrage") 'dans la feuille paramétrage
'comme on va boucler de la colonne 4 à la dernière colonne, on stocke le n° de la dern colonne :
Col = .Cells(1, .Cells.Columns.Count).End(xlToLeft).Column
'on cherche colonne A le nom d'utilisateur saisi et on stocke son num de ligne
Lig = .Columns(1).Cells.Find(Utilisateur, lookat:=xlWhole).Row
'boucle à partir de 3 car Feuil1 toujours affichée
For i = 3 To Col
If UCase(.Cells(Lig, i)) = "X" Then

Sheets(.Cells(1, i).Value).Visible = True 'on affiche la feuille

Else
Sheets(.Cells(1, i).Value).Visible = xlSheetVeryHidden 'sinon on la masque

End If
Next i
End With
End Sub
Sub test()
Sheets("parametrage").Visible = True
End Sub
 

Statistiques des forums

Discussions
312 294
Messages
2 086 881
Membres
103 404
dernier inscrit
sultan87