Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

insérer image à l'impression [vba XL2000], puis l'effacer

6 réponses
Avatar
J
Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:\whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub

Merci pour toute suggestion.
J@@

6 réponses

Avatar
DanielCo
Bonjour,
Remplace activesheet par le nom de la feuille :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
For Each sh In Array("Feuil1", "Feuil3")
Set img = Sheets(sh).Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub

Cordialement.
Daniel


J@@ a écrit
Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub

Merci pour toute suggestion.
J@@
Avatar
J
Bonjour Daniel
et merci pour l'aide, mais

1 - j'ai une erreur 9 sur la ligne
Set img = Sheets(sh).Pictures.Insert(Photo)

2 - je ne connais pas le détail de l'array, il s'agit plutôt de
ActiveWorkbook.Windows(1).SelectedSheets
que l'utilisateur groupe.

Vois-tu comment faire ?
Merci
J@@


Le 30/03/2011 21:58, DanielCo a écrit :
Bonjour,
Remplace activesheet par le nom de la feuille :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
For Each sh In Array("Feuil1", "Feuil3")
Set img = Sheets(sh).Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub

Cordialement.
Daniel


J@@ a écrit
Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub

Merci pour toute suggestion.
J@@




Avatar
DanielCo
Alors plutôt :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sh As Worksheet
Photo = "C:whologo.gif"
Photo = "C:Documents and SettingsMoiMes documentsMes
imagesNeigeDSC00573.JPG"
For Each sh In Windows(1).SelectedSheets
Set img = sh.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub

Daniel


Bonjour Daniel
et merci pour l'aide, mais

1 - j'ai une erreur 9 sur la ligne
Set img = Sheets(sh).Pictures.Insert(Photo)

2 - je ne connais pas le détail de l'array, il s'agit plutôt de
ActiveWorkbook.Windows(1).SelectedSheets
que l'utilisateur groupe.

Vois-tu comment faire ?
Merci
J@@


Le 30/03/2011 21:58, DanielCo a écrit :
Bonjour,
Remplace activesheet par le nom de la feuille :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
For Each sh In Array("Feuil1", "Feuil3")
Set img = Sheets(sh).Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub

Cordialement.
Daniel


J@@ a écrit
Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub

Merci pour toute suggestion.
J@@
Avatar
MichD
Bonjour,

Une autre variante : à mettre dans le ThisWorkbook

'-------------------------------------------------
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sh As Worksheet, Photo As String, T()
Dim A As Integer, Img As Picture, Elt As Variant

'Chemin et nom du fichier image
Photo = "C:whologo.gif"
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each sh In ActiveWindow.SelectedSheets
ReDim Preserve T(A)
T(A) = sh.Name
A = A + 1
Next
Worksheets(T(0)).Select

For Each Elt In T
With Worksheets(Elt)
Set Img = .Pictures.Insert(Photo)
Img.Left = .Range("a2").Left
Img.Top = .Range("a2").Top
.PrintPreview 'après test, tu modifies pour .PrintOut
Cancel = True
Img.Delete
End With
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
'-------------------------------------------------

MichD
--------------------------------------------
"J@@" a écrit dans le message de groupe de discussion : in0u6s$hdc$

Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub

Merci pour toute suggestion.
J@@
Avatar
J
Bonjour MichD
Parfait
Merci beaucoup
@+
Cordialement
J@@

Le 31/03/2011 03:36, MichD a écrit :
Bonjour,

Une autre variante : à mettre dans le ThisWorkbook

'-------------------------------------------------
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sh As Worksheet, Photo As String, T()
Dim A As Integer, Img As Picture, Elt As Variant

'Chemin et nom du fichier image
Photo = "C:whologo.gif"
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each sh In ActiveWindow.SelectedSheets
ReDim Preserve T(A)
T(A) = sh.Name
A = A + 1
Next
Worksheets(T(0)).Select

For Each Elt In T
With Worksheets(Elt)
Set Img = .Pictures.Insert(Photo)
Img.Left = .Range("a2").Left
Img.Top = .Range("a2").Top
.PrintPreview 'après test, tu modifies pour .PrintOut
Cancel = True
Img.Delete
End With
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
'-------------------------------------------------

MichD
--------------------------------------------
"J@@" a écrit dans le message de groupe de discussion : in0u6s$hdc$

Bonjour à tous
Le code suivant fonctionne parfaitement pour *1* feuille
Mais si je groupe plusieurs feuilles, l'image n'est copiée que sur la
première.
Que faire, svp ?

Le but est de garder un fichier léger et d'effacer l'image après
l'impression.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
Set img = ActiveSheet.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
End Sub
Avatar
J
Bonjour Daniel
Excellent
cela fonctionne parfaitement
merci
@+
Cordialement
J@@


Le 31/03/2011 03:11, DanielCo a écrit :
Alors plutôt :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sh As Worksheet
Photo = "C:whologo.gif"
Photo = "C:Documents and SettingsMoiMes documentsMes
imagesNeigeDSC00573.JPG"
For Each sh In Windows(1).SelectedSheets
Set img = sh.Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub

Daniel


Bonjour Daniel
et merci pour l'aide, mais

1 - j'ai une erreur 9 sur la ligne
Set img = Sheets(sh).Pictures.Insert(Photo)

2 - je ne connais pas le détail de l'array, il s'agit plutôt de
ActiveWorkbook.Windows(1).SelectedSheets
que l'utilisateur groupe.


Le 30/03/2011 21:58, DanielCo a écrit :
Bonjour,
Remplace activesheet par le nom de la feuille :

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Photo = "C:whologo.gif"
For Each sh In Array("Feuil1", "Feuil3")
Set img = Sheets(sh).Pictures.Insert(Photo)
img.Left = [a2].Left
img.Top = [a2].Top
Next
End Sub