Mandag, 29 March 2021
  0 Svar
  2.8K besøg
0
Stemmer
Fortryd
Hej, jeg bruger din kode til at sende et Excel-interval som en vedhæftet fil i e-mail, men får en runtime-fejl, hvis jeg annullerer rækken. Er der kode, jeg kan tilføje, eller en msgbox for at forhindre, at dette sker? Tak kode nedenfor.

Sub SendRange()
Dim xFile As String
Dim xFormat så længe
Dim Wb Som arbejdsbog
Dim Wb2 Som arbejdsbog
Dim Ws Som arbejdsark
Dim FilePath som streng
Dim filnavn som streng
Dæmp OutlookApp som objekt
Dæmp OutlookMail som objekt
Dæmp WorkRng As Range
xTitleId = "Eksempel"
Set WorkRng = Application.Selection
Indstil WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Indstil Wb = Application.ActiveWorkbook
Wb.Worksheets.Add
Indstil Ws = Application.ActiveSheet
WorkRng.Copy Ws.Cells(1, 1)
Ws.Copy
Indstil Wb2 = Application.ActiveWorkbook
Vælg Case Wb.FileFormat
Case xlOpenXMLWorkbook:
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
Sag xlOpenXMLWorkbookMacroEnabled:
    Hvis Wb2.HasVBProject Så
        xFile = ".xlsm"
        xFormat = xlOpenXMLWorkbookMacroEnabled
    Else
        xFile = ".xlsx"
        xFormat = xlOpenXMLWorkbook
    End If
Case Excel8:
    xFile = ".xls"
    xFormat = Excel8
Case xlExcel12:
    xFile = ".xlsb"
    xFormat = xlExcel12
Afslut Vælg
FilePath = Environ$("temp") & "\"
Filnavn = Wb.Name & Format(Nu, "dd-mmm-åå h-mm-ss")
Indstil OutlookApp = CreateObject("Outlook.Application")
Indstil OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
Med OutlookMail
    .Til = ""
    .CC = ""
    .BCC = ""
    .Subject = "Tests"
    .Body = "Hej ."
    .Attachments.Add Wb2.FullName
    .Sende
Slut med
Wb2.Luk
Dræb FilePath & FileName & xFile
Indstil OutlookMail = Ingenting
Indstil OutlookApp = Ingenting
Ws.Slet
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
Der er endnu ingen svar på dette indlæg.