Maandag 29 maart 2021
  0 Antwoorden
  2.8K bezoeken
Hallo, ik gebruik uw code om een ​​bereik in Excel per e-mail te verzenden. Als ik het bereik annuleer, krijg ik een runtime-fout. Is het mogelijk om wat code of msgbox toe te voegen om dit te voorkomen en ook om de kolommen op bijlage automatisch aan te passen. Een deel van de code staat hieronder:
Bedankt/media/kunena/emoticons/smile.png

Dim xFile als string
Dim xFormaat zo lang
Dim Wb als werkboek
Dim Wb2 als werkboek
Dim Ws als werkblad
Dim FilePath als string
Dim FileName As String
Dim Outlook-app als object
Dim OutlookMail als object
Dim WorkRng als bereik
xTitleId = "Voorbeeld"
Set WorkRng = Toepassing.Selectie
Set WorkRng = Application.InputBox("Bereik", xTitleId, WorkRng.Address, Type:=8)

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Stel Wb = Application.ActiveWorkbook in
Wb.Werkbladen.Toevoegen
Stel Ws = Application.ActiveSheet in
WorkRng.Kopieer Ws.Cells(1, 1)
Ws.Kopieer
Stel Wb2 = Application.ActiveWorkbook in
Selecteer Case Wb.Bestandsindeling
Case xlOpenXMLWerkboek:
    xFile = ".xlsx"
    xFormat = xlOpenXMLWerkmap
Case xlOpenXMLWorkbookMacroIngeschakeld:
    Als Wb2.HasVBProject Dan
        xFile = ".xlsm"
        xFormat = xlOpenXMLWorkbookMacroEnabled
    Anders
        xFile = ".xlsx"
        xFormat = xlOpenXMLWerkmap
    End If
Geval Excel8:
    xFile = ".xls"
    xFormaat = Excel8
Geval xlExcel12:
    xFile = ".xlsb"
    xFormaat = xlExcel12
End Select
Er zijn nog geen reacties op dit bericht geplaatst.