Hi,
I clean up your code a bit along the way:
ThisWorkbook:
Option Explicit
Dim cControl As CommandBarButton
Private Sub Workbook_AddinInstall()
On Error Resume Next 'Just in case
With Application
.CommandBars("Worksheet Menu Bar").Controls("Super Code").Delete 'Delete any existing menu item that may have been left.
Set cControl = .CommandBars("Worksheet Menu Bar").Controls.Add 'Add the new menu item and Set a CommandBarButton Variable to it
End With
' Work with the Variable
With cControl
.Caption = "Super Code"
.Style = msoButtonCaption
.OnAction = "Module1" 'Macro stored in a Standard Module
End With
On Error GoTo 0
End Sub
Private Sub Workbook_AddinUninstall()
On Error Resume Next 'In case it has already gone.
Application.CommandBars("Worksheet Menu Bar").Controls("Super Code").Delete
On Error GoTo 0
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Worksheets("Main form").Range("B2:B220")) Is Nothing Then Mail
End Sub
Module1:
Sub Deter()
Dim vData As Range, buf As String
For Each vData In Range("C:C").SpecialCells(xlFormulas, 2)
buf = buf & ";" & vData
Next vData
Range("E8").Value = Mid(buf, 2, Len(buf))
End Sub
Sub Clear()
Range("B2:B22", "E8").ClearContents
Range("B2").Select
End Sub
Sub Mail()
Dim OutlookApp As Object
Dim Mess As Object, Recip
Recip = Range("E8")
Set OutlookApp = CreateObject("Outlook.Application")
Set Mess = OutlookApp.CreateItem(olMailItem)
With Mess
.Subject = Range("E10")
.Body = Range("E12")
.To = Recip
.Display
End With
End Sub
Sub Clearing()
Range("B2, E8, E10, E12:I17").ClearContents
Range("B2").Select
End Sub
Sub Clearingd()
Range("B2:B220, E8, E10, E12:I17").ClearContents
Range("B2").Select
End Sub
Test and let me know if you need any tweaks.
Bookmarks