Pièces jointes VBA

Fermé
JO882161 Messages postés 6 Date d'inscription mercredi 4 janvier 2017 Statut Membre Dernière intervention 5 janvier 2017 - 4 janv. 2017 à 19:00
JO882161 Messages postés 6 Date d'inscription mercredi 4 janvier 2017 Statut Membre Dernière intervention 5 janvier 2017 - 5 janv. 2017 à 16:09
Bonjour,

Pourquoi je n'arrive pas à envoyer des pièces jointes ?

'Envoie de l'email : eMail

Private Sub CommandButton1_Click()

'Working in Excel 2002-2016
Dim AWorksheet As Worksheet
Dim Sendrng As Range
Dim rng As Range


On Error GoTo StopMacro

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Fill in the Worksheet/range you want to mail
'Note: if you use one cell it will send the whole worksheet
Set Sendrng = Worksheets("Mail").Range("A1:G23")

'Remember the activesheet
Set AWorksheet = ActiveSheet

With Sendrng

' Select the worksheet with the range you want to send
.Parent.Select

'Remember the ActiveCell on that worksheet
Set rng = ActiveCell

'Select the range you want to mail
.Select

' Create the mail and send it
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope

' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Produktionsanleitung für Klusi."

With .Item
.To = Worksheets("Mail").Range("B23")
.CC = ""
.BCC = ""
.Subject = "Klusi"
.Attachements.Add ("Q:\ZLS-Command_Temp\UST Mühleberg Duplex 16kV Ltg. Illiswil")
.Send ' envoie automatique
End With

End With

'select the original ActiveCell
rng.Select
End With

'Activate the sheet that was active before you run the macro
AWorksheet.Select

StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
'ActiveWorkbook.EnvelopeVisible = False

End Sub


2 réponses

yg_be Messages postés 22720 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 23 avril 2024 1 476
Modifié par yg_be le 4/01/2017 à 20:43
Tu as un message d'erreur?
Ce n'est pas la présence d'espaces dans le nom qui cause le problème?
0
JO882161 Messages postés 6 Date d'inscription mercredi 4 janvier 2017 Statut Membre Dernière intervention 5 janvier 2017
5 janv. 2017 à 12:48
Non pas de message d'erreur ;)
0
yg_be Messages postés 22720 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 23 avril 2024 1 476
5 janv. 2017 à 13:31
Le mail est envoyé sans fichier attaché?
0
JO882161 Messages postés 6 Date d'inscription mercredi 4 janvier 2017 Statut Membre Dernière intervention 5 janvier 2017
5 janv. 2017 à 15:14
en effet :) ja'i fais Ctrl C @ V qui n'as pas marché. Grrrrrrrrrrrr.

Sais-tu si y a possibilité d'envoyé juste une feuille de mon fichier excel ?
0
yg_be Messages postés 22720 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 23 avril 2024 1 476
5 janv. 2017 à 15:22
Je pense qu'il faut créer un nouveau fichier ne contenant qu'une feuille, et puis attacher ce fichier au mail.
0
JO882161 Messages postés 6 Date d'inscription mercredi 4 janvier 2017 Statut Membre Dernière intervention 5 janvier 2017
5 janv. 2017 à 15:45
Par exemple :

With .Item
.To = Worksheets("Mail").Range("B23")
.CC = ""
.BCC = ""
.Subject = "Klusi"
.Attachments.Add = Worksheets("Mail")
.Send ' envoie automatique

End With
0
yg_be Messages postés 22720 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 23 avril 2024 1 476
5 janv. 2017 à 15:56
Non, c'est plus compliqué.
0