Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CheckBox2_Click()
- ChangeCheckBoxValue "CheckBox2"
- If (ActiveSheet.CheckBoxes("CheckBox2").Value = True) Then
- EnableCheckbox "CheckBox3"
- DisableCheckbox "CheckBox2"
- Else
- EnableCheckbox "CheckBox2"
- DisableCheckbox "CheckBox3"
- End If
- SendEmail "szymon.kolanowski@suez.com"
- End Sub
- Sub CheckBox3_Click()
- ChangeCheckBoxValue "Check Box 3"
- If (ActiveSheet.CheckBoxes("Check Box 3").Value = True) Then
- EnableCheckbox "Check Box 4"
- DisableCheckbox "Check Box 3"
- Else
- EnableCheckbox "Check Box 3"
- DisableCheckbox "Check Box 4"
- End If
- SendEmail "s.kolano@amorki.pl"
- End Sub
- Sub ChangeCheckBoxValue(checkBoxName)
- Dim checkBoxValue As Boolean
- checkBoxValue = ActiveSheet.CheckBoxes(checkBoxName).Value
- If (checkBoxValue = True) Then
- ActiveSheet.CheckBoxes(checkBoxName).Value = False
- Else
- ActiveSheet.CheckBoxes(checkBoxName).Value = True
- End If
- End Sub
- Sub EnableCheckbox(checkBoxName)
- ActiveSheet.CheckBoxes(checkBoxName).Enabled = True
- End Sub
- Sub DisableCheckbox(checkBoxName)
- For Each cb In ActiveSheet.Shapes
- If cb.Name = checkBoxName Then
- Else
- If cb.Type = msoFormControl Then
- If cb.FormControlType = xlCheckBox Then
- cb.ControlFormat.Enabled = False
- End If
- End If
- End If
- ActiveSheet.CheckBoxes(checkBoxName).Enabled = False
- Next cb
- End Sub
- Sub SendEmail(toAddress As String)
- On Error Resume Next
- Dim iMsg As Object, iConf As Object
- Const SendUsingPort = 2
- Set iMsg = CreateObject("CDO.Message")
- Set iConf = CreateObject("CDO.Configuration")
- Set wb1 = ActiveWorkbook
- 'Make a copy of the file/Open it/Mail it/Delete it
- 'If you want to change the file name then change only TempFileName
- TempFilePath = Environ$("temp") & "\"
- TempFileName = wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
- FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
- wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
- 'konfiguracja
- With iConf.Fields
- .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = SendUsingPort
- .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.48.1.115"
- .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
- .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0
- .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 0
- .Update
- End With
- 'wiadomość
- With iMsg
- Set .Configuration = iConf
- .TextBody = "Zerknij do załącznika"
- .Subject = "Wypełnij załącznik"
- .From = "helpdesk.polska@suez.com"
- .To = toAddress
- .AddAttachment TempFilePath & TempFileName & FileExtStr
- .Send
- End With
- Set iMsg = Nothing
- Set iConf = Nothing
- 'obsługa błędów
- If Err.Number <> 0 Then
- If Err.Number = &H80040213 Then
- MsgBox Err.Description, 48, "Błąd serwera SMTP"
- Else
- MsgBox Err.Description, 48, "Błąd Hx" & Hex(Err.Number)
- End If
- Else
- MsgBox "OK, wysłano.", 64
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement