Function

echo0001

Registered User.
Local time
Today, 23:11
Joined
Aug 30, 2008
Messages
55
Hello

Im new to VBA and i would like help with getting a macro to run a VB script. i have tryed runcode but the marco cannot find my module as function.

Can anyone help.
 
You put your function in a stand alone code module (Not a form or report code module) and call it from a macro.
 
It is in a standalone module. this is the code i have is it because of this.

Option Compare Database
Option Explicit
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute
' your names here.
Set objOutlookRecip = .Recipients.Add("Matthew Horlock")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("")
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add("C:\Documents and Settings\Brendan.Mills\Desktop\Equipment DB\Item due for calibration.rtf")
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
ErrorMsgs:
If Err.Number = "287" Then

Else

End If
End Sub
 
You've created a sub procedure, not a function. :)
 
Public Function fncSendMessage()

>some code<

End Function
 

Users who are viewing this thread

Back
Top Bottom