Bonjour, j'utilise votre code pour envoyer une plage dans Excel par e-mail. Si j'annule la plage, j'obtiens une erreur d'exécution. Est-il possible d'ajouter du code ou msgbox pour éviter cela s'il vous plaît et aussi pour ajuster automatiquement les colonnes sur la pièce jointe. Une partie du code est ci-dessous
Merci/media/kunena/emoticons/sourire.png
Estomper xFile en tant que chaîne
Dim xFormat aussi longtemps
Dim Wb comme classeur
Dim Wb2 en tant que classeur
Feuille de travail Dim Ws As
Dim FilePath en tant que chaîne
Dim FileName As String
Dim OutlookApp en tant qu'objet
Dim OutlookMail en tant qu'objet
Dim WorkRng comme plage
xTitleId = "Exemple"
Set WorkRng = Application.Selection
Définir WorkRng = Application.InputBox("Plage", xTitleId, WorkRng.Address, Type :=8)
Application.ScreenUpdating = Faux
Application.DisplayAlerts = Faux
Définir Wb = Application.ActiveWorkbook
Wb.Worksheets.Add
Définir Ws = Application.ActiveSheet
WorkRng.Copie Ws.Cells(1, 1)
Ws. Copier
Définir Wb2 = Application.ActiveWorkbook
Sélectionnez Case Wb.FileFormat
Cas xlOpenXMLWorkbook :
xFichier = ".xlsx"
xFormat = xlOpenXMLWorkbook
Cas xlOpenXMLWorkbookMacroEnabled :
Si Wb2.HasVBProject Alors
xFichier = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
autre
xFichier = ".xlsx"
xFormat = xlOpenXMLWorkbook
Si fin
Cas Excel8 :
xFichier = ".xls"
xFormat = Excel8
Cas xlExcel12 :
xFichier = ".xlsb"
xFormat = xlExcel12
End Select
Merci/media/kunena/emoticons/sourire.png
Estomper xFile en tant que chaîne
Dim xFormat aussi longtemps
Dim Wb comme classeur
Dim Wb2 en tant que classeur
Feuille de travail Dim Ws As
Dim FilePath en tant que chaîne
Dim FileName As String
Dim OutlookApp en tant qu'objet
Dim OutlookMail en tant qu'objet
Dim WorkRng comme plage
xTitleId = "Exemple"
Set WorkRng = Application.Selection
Définir WorkRng = Application.InputBox("Plage", xTitleId, WorkRng.Address, Type :=8)
Application.ScreenUpdating = Faux
Application.DisplayAlerts = Faux
Définir Wb = Application.ActiveWorkbook
Wb.Worksheets.Add
Définir Ws = Application.ActiveSheet
WorkRng.Copie Ws.Cells(1, 1)
Ws. Copier
Définir Wb2 = Application.ActiveWorkbook
Sélectionnez Case Wb.FileFormat
Cas xlOpenXMLWorkbook :
xFichier = ".xlsx"
xFormat = xlOpenXMLWorkbook
Cas xlOpenXMLWorkbookMacroEnabled :
Si Wb2.HasVBProject Alors
xFichier = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
autre
xFichier = ".xlsx"
xFormat = xlOpenXMLWorkbook
Si fin
Cas Excel8 :
xFichier = ".xls"
xFormat = Excel8
Cas xlExcel12 :
xFichier = ".xlsb"
xFormat = xlExcel12
End Select