nmgmarques
Board Regular
- Joined
- Mar 1, 2011
- Messages
- 133
- Office Version
- 365
- Platform
- Windows
Hi guys.
Trying to get this script to work using snippets found scouring the web. The macro saves the file using values in D6 and G6 as filename and thenattempts to send an email to users notifying them of the new file. However the code breaks at
It throws a "Compile error: User-defined type not defined" and pressing ok highlights
This is the full code thus far:
Any help appreciated!
Trying to get this script to work using snippets found scouring the web. The macro saves the file using values in D6 and G6 as filename and thenattempts to send an email to users notifying them of the new file. However the code breaks at
Code:
Dim olns As Outlook.Namespace
It throws a "Compile error: User-defined type not defined" and pressing ok highlights
Code:
olns As Outlook.Namespace
This is the full code thus far:
Code:
Sub SaveAsExample()
' Gravar ficheiro com nome igual ao número de ECM e indicar se é Não Aplicável
Dim FName As String
Dim FPath As String
Dim NApl As String
FPath = "L:\10_CBR_Common\Assuntos gerais\Gestão ECM"
FName = Sheets("ECM").Range("D6").Text
NApl = Sheets("ECM").Range("G6").Text
ThisWorkbook.SaveAs Filename:=FPath & "\" & FName & "_" & NApl
'Enviar email de notificação
Dim strReportName As String
Dim oLook As Object
Dim oMail As Object
Dim olns As Outlook.Namespace
Dim strTO As String
Dim strCC As String
Dim strMessageBody As String
Dim strSubject As String
Set oLook = CreateObject("Outlook.Application")
'Set olns = oLook.GetNamespace("MAPI")
Set oMail = oLook.CreateItem(0)
'*********************** USER DEFINED SECTION ************************
strTO = "mymail@gmail.com;mymail2@gmail.com;mymail3@gmail.com"
strMessageBody = "Criada nova Ficha de Acompanhamento e Implementação de ECM"
strSubject = "Ficheiro Acompanhamento ECM " & FName & "_" & NApl
'*********************************************************************
With oMail
.To = strTO
.CC = strCC
.Body = strMessageBody
.Subject = strSubject
.Attachments.Add FPath & "\" & FName & "_" & NApl
.Send
End With
Set oMail = Nothing
Set oLook = Nothing
'Set olns = Nothing
'DB.Close
'tbloutput.Close
'dbLocal.Close
objWorkbook.Close
'Set objmail = Nothing
'Set DB = Nothing
Set tbloutput = Nothing
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
Set tbloutput = Nothing
Set dbLocal = Nothing
End Sub
Any help appreciated!