Problem with VBA script in excel workbook

Gmember

New Member
Joined
Jul 16, 2018
Messages
1
Hello,

I hope someone can help me out, i have very little know-how in excel and VBA so i hope i can get some answers regarding a problem i have.

I have this (read only) excel sheet for ordering parts and such, after selecting all the parts it makes a collection sheet ready to send thru mail.
No problem so far.

Now the troubles begin, when i press the "send" button it runs a VBA script to send the sheet to a specific mail adress and when the mail transfer ends the excel sheet crashes when closing and restarts and try's to recover all closed excel files.
The mail does work, but it's really annoying, specially when there are more excel sheets open because they close to.

There must be something wrong in this mail VBA script, for now i don't send the collection sheet thru the "send" button in excel but copy the sheet in a new sheet and safe it to the desktop to send it manually with outlook. This way i can close the excel without crashing excel.

Below the VBA mail Script:


Code:
Sub MailenProjects()
 ' Stuurt de bestelling van materiaal, uitbesteed werk en andere soorten bestellingen door naar het Ticket-Systeem
     Dim DateStr As String
     Dim TempName As String
     Dim EmailName As String
     Dim MsgVal As String
    
     Dim CurrWB As Workbook
     Dim CurrSheet As Worksheet
     Dim TempWB As New Workbook
     Dim TempSheet As Worksheet


     DateStr = CStr(Now)
     TempName = Environ("temp") & "\Verzamelblad.xls"


     Set CurrWB = ActiveWorkbook
     Set CurrSheet = CurrWB.ActiveSheet


     MsgVal = MsgBox("Onvolledige Bestellingen Lopen Vertraging Op", _
     vbYesNo, "Verzamellijst verzenden")


     If MsgVal = 6 Then
       
         Set TempWB = Excel.Application.Workbooks.Add
         TempWB.SaveAs TempName
         Set TempSheet = TempWB.Sheets(1)
          
         CurrWB.Activate
         CurrSheet.Activate
         CurrSheet.Range("O1:Z500").Copy
        
         TempWB.Activate
         TempSheet.Activate
         TempSheet.Range("A1").Activate


         TempSheet.Paste
         Application.CutCopyMode = False


         TempSheet.Range("A1").ColumnWidth = CurrSheet.Range("O1").ColumnWidth
         TempSheet.Range("B1").ColumnWidth = CurrSheet.Range("P1").ColumnWidth
         TempSheet.Range("C1").ColumnWidth = CurrSheet.Range("Q1").ColumnWidth
         TempSheet.Range("D1").ColumnWidth = CurrSheet.Range("R1").ColumnWidth
         TempSheet.Range("E1").ColumnWidth = CurrSheet.Range("S1").ColumnWidth
         TempSheet.Range("F1").ColumnWidth = CurrSheet.Range("T1").ColumnWidth
         TempSheet.Range("G1").ColumnWidth = CurrSheet.Range("U1").ColumnWidth
         TempSheet.Range("H1").ColumnWidth = CurrSheet.Range("V1").ColumnWidth
         TempSheet.Range("I1").ColumnWidth = CurrSheet.Range("W1").ColumnWidth
         TempSheet.Range("J1").ColumnWidth = CurrSheet.Range("X1").ColumnWidth
         TempSheet.Range("K1").ColumnWidth = CurrSheet.Range("Y1").ColumnWidth
         TempSheet.Range("L1").ColumnWidth = CurrSheet.Range("Z1").ColumnWidth
         TempSheet.Range("M1").ColumnWidth = CurrSheet.Range("AA1").ColumnWidth


         EmailName = "Justatest@test.com"
        
         TempWB.Activate
         Excel.Application.WindowState = xlMinimized
         TempWB.SendMail EmailName, "Materiaal Bestelling: " & DateStr
         Excel.Application.WindowState = xlNormal
         TempWB.Close False
        
         MsgBox "BEVESTIGING" _
         & vbCrLf & "" _
         & vbCrLf & "Bedankt voor Uw bestelling." _
         & vbCrLf & "Deze is doorgemaild naar de nieuwe sourcing mailbox." _
         & vbCrLf & "Uw bestelling zal zo spoedig mogelijk behandeld worden." _
         & vbCrLf & "Indien de status van de bestelling wijzigt," _
         & vbCrLf & "wordt u per mail geïnformeerd o.v.v. het juiste ticket." _
         & vbCrLf & "" _
         & vbCrLf & "" _
         & vbCrLf & "Heeft u vragen over uw bestelling," _
         & vbCrLf & "stuur dan een mail naar:" _
         & vbCrLf & "Justatest@test.com" _
         & vbCrLf & "met in het onderwerp van de mail uw ticket (##xxx##)."


        Set CurrSheet = Nothing
         Set CurrWB = Nothing
         Kill TempName
     End If
 End Sub
 
Last edited by a moderator:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top