Bonjour à tous,

Je me permets de venir poster ici car il m'arrive une chose inexplicable...

j'ai déclaré ma variable comme suit

C'est une variable placé en amont du début de la macro

Ensuite dans la macro, je l'initialise et je l'incrémente pour m'en servir dans le nommage de mon fichier que j'enregistre :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Sub expdos()
 
Dim MonDossier As String
 
MonDossier = ThisWorkbook.Path & "\Export\"
 
If Len(Dir(MonDossier, vbDirectory)) = 0 Then
    MkDir (ThisWorkbook.Path & "\Export\")
End If
 
'je teste voir si la macro a déjà été lancée pour initialisé nSheet et nbimg
If exp <> "Ok" Then
    nSheet = ActiveSheet.Name
    nbimg = 0
End If
 
'c'est ici où ça bug, ça ne veut pas incrémenter nbimg mais j'ai bien la msgbox qui s'active me confirmant que je suis bien dans la condition du If
If nSheet = ActiveSheet.Name Then
    nbimg = nbimg + 1
    MsgBox nbimg & " i"
Else
    nSheet = ActiveSheet.Name
    nbimg = 0
End If
 
ActiveWindow.DisplayGridlines = False
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 
With ActiveSheet.ChartObjects.Add(Left:=Selection.Left, Top:=Selection.Top, Width:=Selection.Width, Height:=Selection.Height)
    .Name = "ExportImage"
    .Activate
End With
ActiveChart.Paste
FichierImage = MonDossier & nSheet & "_" & nbimg & ".jpg"
ActiveSheet.ChartObjects("ExportImage").Chart.Export FichierImage
ActiveSheet.ChartObjects("ExportImage").Delete
 
Application.ScreenUpdating = True
End Sub
Vous remerciant par avance.