Ciao Norman...purtroppo oggi la macro non mi funziona piú.
settimana scorsa ho fatto delle modifiche e non so dove ho sbagliato.
al momento la macro mi crea solo il documento nuovo ma non mi apre l´outlook per inviare la mail.
potresti cortesemente dare una occhiata?
e un´altra cosa: sinceramente quella parte che "parla" della password non l´ho capita..... come dovrebbe funzionare; a me non ha mai chiesto nulla
e anche la parte segnata in verde non sono mai riuscito a farla andare.
Grazie Ivan
'=========>>
Option Explicit
'--------->>
Public Sub AvvisoRundlauf()
Dim srcWB As Workbook
Dim destWB As Workbook
Dim srcSH As Worksheet
Dim Rng As Range, srcRng As Range
Dim sFilename As String
Dim sExt As String
Dim oOutlook As Object
Dim oMail As Object
Dim bProtected As Boolean
Const sPassword As String = "Ivan"
Const sNomeFileAllegato As String = "TPM"
Const sEmail As String = \_
"Luca.Oliva@xxxx\*\*\*\*"
Const sCc As String = \_
"Thomas.Fischer@xxxx\*\*\*\*"
Const sOggetto As String \_
= "Controllo Spindel Rundlauf"
Const sCorpo As String \_
= "Prego controllare il Rundlauf del mandrino"
Set srcWB = ThisWorkbook
Set srcSH = ActiveSheet
Set Rng = Selection
With srcSH
bProtected = srcSH.ProtectContents = True
If bProtected Then
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
Set srcRng = Rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If srcRng Is Nothing Then
Call MsgBox( \_
Prompt:="La selezione non è un intervallo!" \_
& vbNewLine & vbNewLine \_
& "Seleziona l'intervallo di interesse e ripova", \_
Buttons:=vbCritical, \_
Title:="REPORT")
Exit Sub
End If
On Error GoTo XIT
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set destWB = Workbooks.Add(xlWBATWorksheet)
srcRng.Copy
With destWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8 '\\ xlPasteColumnWidths
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(0)
sFilename = sNomeFileAllegato & "\_" \_
& Format(Now, "dd-mmm-yy hh-mm-ss")
sExt = ".xlsx"
With destWB
.SaveAs Filename:=sFilename & sExt, \_
FileFormat:=51
On Error Resume Next
With oMail
.to = sEmail
.CC = sCc
.BCC = ""
.Subject = sOggetto & " " & srcSH.Name
.Body = sCorpo
.Attachments.Add destWB.FullName
.Display '.Send
End With
On Error GoTo 0
.Close savechanges:=False
End With
Kill sFilename & sExt
XIT:
Set oMail = Nothing
Set oOutlook = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
'<<=========