OVH Cloud OVH Cloud

export par mail special

1 réponse
Avatar
Jacquouille Le Gaulois
Bonjour,

J'utilise un fichier de Pierre Wautier avec la macro ci-dessous et je
voudrais l'ameliorer mais je n y arrive pas.
1-Je voudrais que seul les lignes avec des donnees en colonne A soient
selectionnees (dans la plage A1:AI48)

2-Je voudrais que ce nouveau classeur soit envoye par mail à une
adresse defini dans ma feuille "Parametre" en cellule "C15"
3-J aimerais que le classeur en piece jointe porte le nom de la feuille
exporte et non pas "ClasseurX.xls"

Merci
Sub transfert_réseau_DSIP()
'
ActiveSheet.Unprotect
Application.GoTo Reference:="R1C1"
Range("A1:AI48").Select
Application.CutCopyMode = False
Selection.Copy
Workbooks.Add
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=-21
Columns("A:A").EntireColumn.AutoFit
Columns("A:A").ColumnWidth = 3.44
Columns("A:A").ColumnWidth = 4.44
Columns("B:B").EntireColumn.AutoFit
Application.CutCopyMode = False
Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False
Columns("C:AI").Select
Selection.ColumnWidth = 2.3
Range("A1").Select
With ActiveWindow
.DisplayGridlines = False
.DisplayZeros = False
End With
ActiveWindow.SmallScroll Down:=-6
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.787401575)
.RightMargin = Application.InchesToPoints(0.787401575)
.TopMargin = Application.InchesToPoints(0.984251969)
.BottomMargin = Application.InchesToPoints(0.984251969)
.HeaderMargin = Application.InchesToPoints(0.4921259845)
.FooterMargin = Application.InchesToPoints(0.4921259845)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.79)
.RightMargin = Application.InchesToPoints(0.79)
.TopMargin = Application.InchesToPoints(0.98)
.BottomMargin = Application.InchesToPoints(0.53)
.HeaderMargin = Application.InchesToPoints(0.49)
.FooterMargin = Application.InchesToPoints(0.49)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.79)
.RightMargin = Application.InchesToPoints(0.79)
.TopMargin = Application.InchesToPoints(0.54)
.BottomMargin = Application.InchesToPoints(0.53)
.HeaderMargin = Application.InchesToPoints(0.49)
.FooterMargin = Application.InchesToPoints(0.49)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintPreview
Application.Dialogs(xlDialogSendMail).Show
ActiveWindow.Close
ActiveWindow.SmallScroll Down:=-27
Range("C5").Select
ActiveSheet.Protect DrawingObjects:=False, Contents:=True,
Scenarios:=False
End Sub

--
("|`-''-/").___..--''"`-._
`6_ 6 ) `-. ( ).`-.__.`)
(_Y_.)' ._ ) `._ `. ``-..-'
_..`--'_..-_/ /--'_.' ,'
(il),-'' (li),' ((!.-'

1 réponse

Avatar
Frédéric Sigonneau
Bonjour,

Peut-être cette proposition de code pourra-t-elle t'aider à avancer dans ton
projet (il faut tout recopier dans un module standard du classeur contenant les
données à exporter, et lancer la procédure transfert_réseau_DSIP après avoir
modifié les paramètres passés à la procédure EnvoiCourriel par tes propres
adresses et nom de serveur smtp valides) :

'============================ Private Declare Function InternetAutodial Lib "Wininet" _
(ByVal dwFlags As Long, ByVal hwndParent As Long) As Long

Private Declare Function InternetAutodialHangup Lib "wininet.dll" _
(ByVal dwReserved As Long) As Long

Public Declare Function InternetGetConnectedState Lib "wininet.dll" _
(lpdwFlags As Long, ByVal dwReserved As Long) As Boolean


Sub transfert_réseau_DSIP()
Dim Wbk, TmpWbk, Chemin$

Set Wbk = ThisWorkbook
ActiveSheet.Unprotect
Application.GoTo Reference:="R1C1"
'plage des données (Q1)
Range(ActiveCell.CurrentRegion.Address).Copy
Set TmpWbk = Workbooks.Add
Range("A1").PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse
Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse
Columns("A:A").ColumnWidth = 4.44
Columns("B:B").EntireColumn.AutoFit
Application.CutCopyMode = False
Columns("C:" & Split(ActiveCell.CurrentRegion.Address, "$")(3)).ColumnWidth = 2.3
With ActiveWindow
.DisplayGridlines = False
.DisplayZeros = False
End With
With ActiveSheet.PageSetup
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'(Q3)
TmpWbk.SaveAs ActiveSheet.Name
Chemin = TmpWbk.FullName
TmpWbk.Close False
'(Q2)
EnvoiCourriel Wbk.Sheets("Parametre").Range("C5").Value, _
"", _
"smtp.wanamou.fr", "test", "", Chemin

ActiveSheet.Protect DrawingObjects:úlse, Contents:=True, Scenarios:úlse
Kill Chemin
End Sub

Sub EnvoiCourriel(Destinataire$, Expéditeur$, ServeurSMTP$, _
Sujet$, TexteMessage$, _
Optional PieceJointe = "")
Dim EtatConnexion As Boolean, Etat As Long

'Se connecter à Internet si ce n'est fait
EtatConnexion = (InternetGetConnectedState(Etat, 0&) <> 0)
If Not EtatConnexion Then
InternetAutodial 1, 0
While Not (InternetGetConnectedState(Etat, 0&) <> 0)
Wend
End If

'Construction et envoi
With CreateObject("CDO.Message")
.From = Expéditeur
.To = Destinataire
.Subject = Sujet
.TextBody = TexteMessage
If PieceJointe <> "" Then .AddAttachment PieceJointe
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
ServeurSMTP
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
.Send
End With

'Remise en l'état initial
If Not EtatConnexion Then InternetAutodialHangup 0&

End Sub 'fs
'============================
FS
--
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Si votre question sur Excel est urgente, évitez ma bal !

Jacquouille Le Gaulois a écrit:
Bonjour,

J'utilise un fichier de Pierre Wautier avec la macro ci-dessous et je
voudrais l'ameliorer mais je n y arrive pas.
1-Je voudrais que seul les lignes avec des donnees en colonne A soient
selectionnees (dans la plage A1:AI48)

2-Je voudrais que ce nouveau classeur soit envoye par mail à une adresse
defini dans ma feuille "Parametre" en cellule "C15"
3-J aimerais que le classeur en piece jointe porte le nom de la feuille
exporte et non pas "ClasseurX.xls"

Merci
Sub transfert_réseau_DSIP()
'
ActiveSheet.Unprotect
Application.GoTo Reference:="R1C1"
Range("A1:AI48").Select
Application.CutCopyMode = False
Selection.Copy
Workbooks.Add
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:úlse
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:úlse
ActiveWindow.SmallScroll Down:=-21
Columns("A:A").EntireColumn.AutoFit
Columns("A:A").ColumnWidth = 3.44
Columns("A:A").ColumnWidth = 4.44
Columns("B:B").EntireColumn.AutoFit
Application.CutCopyMode = False
Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:úlse
Columns("C:AI").Select
Selection.ColumnWidth = 2.3
Range("A1").Select
With ActiveWindow
.DisplayGridlines = False
.DisplayZeros = False
End With
ActiveWindow.SmallScroll Down:=-6
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.787401575)
.RightMargin = Application.InchesToPoints(0.787401575)
.TopMargin = Application.InchesToPoints(0.984251969)
.BottomMargin = Application.InchesToPoints(0.984251969)
.HeaderMargin = Application.InchesToPoints(0.4921259845)
.FooterMargin = Application.InchesToPoints(0.4921259845)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.79)
.RightMargin = Application.InchesToPoints(0.79)
.TopMargin = Application.InchesToPoints(0.98)
.BottomMargin = Application.InchesToPoints(0.53)
.HeaderMargin = Application.InchesToPoints(0.49)
.FooterMargin = Application.InchesToPoints(0.49)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.79)
.RightMargin = Application.InchesToPoints(0.79)
.TopMargin = Application.InchesToPoints(0.54)
.BottomMargin = Application.InchesToPoints(0.53)
.HeaderMargin = Application.InchesToPoints(0.49)
.FooterMargin = Application.InchesToPoints(0.49)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintPreview
Application.Dialogs(xlDialogSendMail).Show
ActiveWindow.Close
ActiveWindow.SmallScroll Down:=-27
Range("C5").Select
ActiveSheet.Protect DrawingObjects:úlse, Contents:=True,
Scenarios:úlse
End Sub