Hello,
I am getting he following error when trying to run this macro. Can someone help me correct it.
"Compile error User-defined type not defined"
The purpose of the vba is to email the latest file from a shared location
Option Explicit
Sub GenerateEmail()
Dim objOutLook As Object
Dim fso As Object
Dim strFile As String
Dim fsoFile
Dim fsoFldr
Dim dtNew As Date, sNew As String
Dim newOutlookInstance As Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
If GetOutlook(objOutLook, newOutlookInstance) Then
strFile = "Z:\Derivative Valuations\Valuation Uploads" 'path to folder
Set fsoFldr = fso.GetFolder(strFile)
dtNew = Now() - TimeValue("01:00:00") '1 hr ago
For Each fsoFile In fsoFldr.Files
If fsoFile.DateCreated > dtNew Then
sNew = fsoFile.Path
With objOutLook.CreateItem(olMailItem)
.To = "test@gmail.om"
.Subject = "Valuations Upload - COB " & Format(DateAdd("d", -1, Date), "dd-mm-yy")
.Body = "Please be advised the following position are missing counterparty prices"
.BodyFormat = olFormatPlain
.Attachments.Add sNew
'.Importance = olImportanceHigh
.Display
End With
End If
Next
If newOutlookInstance Then objOutLook.Quit
Set objOutLook = Nothing
Else
MsgBox "Sorry: couldn't get a valid Outlook instance running"
End If
End Sub
Function GetOutlook(objOutLook As Object, newOutlookInstance As Boolean) As Boolean
End Function
Set objOutLook = GetObject(, "Outlook.Application")
If objOutLook Is Nothing Then
Set objOutLook = New Outlook.Application
newOutlookInstance = True
End If
GetOutlook = Not objOutLook Is Nothing
End Function
End Sub
I am getting he following error when trying to run this macro. Can someone help me correct it.
"Compile error User-defined type not defined"
The purpose of the vba is to email the latest file from a shared location
Option Explicit
Sub GenerateEmail()
Dim objOutLook As Object
Dim fso As Object
Dim strFile As String
Dim fsoFile
Dim fsoFldr
Dim dtNew As Date, sNew As String
Dim newOutlookInstance As Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
If GetOutlook(objOutLook, newOutlookInstance) Then
strFile = "Z:\Derivative Valuations\Valuation Uploads" 'path to folder
Set fsoFldr = fso.GetFolder(strFile)
dtNew = Now() - TimeValue("01:00:00") '1 hr ago
For Each fsoFile In fsoFldr.Files
If fsoFile.DateCreated > dtNew Then
sNew = fsoFile.Path
With objOutLook.CreateItem(olMailItem)
.To = "test@gmail.om"
.Subject = "Valuations Upload - COB " & Format(DateAdd("d", -1, Date), "dd-mm-yy")
.Body = "Please be advised the following position are missing counterparty prices"
.BodyFormat = olFormatPlain
.Attachments.Add sNew
'.Importance = olImportanceHigh
.Display
End With
End If
Next
If newOutlookInstance Then objOutLook.Quit
Set objOutLook = Nothing
Else
MsgBox "Sorry: couldn't get a valid Outlook instance running"
End If
End Sub
Function GetOutlook(objOutLook As Object, newOutlookInstance As Boolean) As Boolean
End Function
Set objOutLook = GetObject(, "Outlook.Application")
If objOutLook Is Nothing Then
Set objOutLook = New Outlook.Application
newOutlookInstance = True
End If
GetOutlook = Not objOutLook Is Nothing
End Function
End Sub