Hello all,
A fellow forum member recently compiled some VBA code for me to run from two separate modules and while the code does work I am not sure how to run code via an Access macro. If I try to call the code in the first module via "RUNCODE" it keeps telling me that I have the wrong number of arguments. In the 2nd module, I know I have to change "SUB" to "FUNCTION" in order for it to work. Can anyone please tell me how I would go about combining the two modules and getting them to run via a macro. Below is the code I currently have:
First module named RptExtras:
Function GetBoiler(ByVal sFile As String) As String
'**** Created by someone else
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Second module named RptAutomation:
Sub sendForApproval1()
'*************************************************
'VBA Code created by Trevor G May 2015
'Updated from previous version
'*************************************************
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim SigString As String
Dim Signature As String
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
SigString = "C:\Users\con04785\AppData\Roaming\Microsoft\S igna tures\Nina.txt"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
With olMail
.To = "nina@email.com"
.Subject = Format(Date, "dd-mmm-yyyy") & " Daily Report"
.Body = "Attached is the latest report update." & vbCr & vbCr & _
"Thank you." & vbCr & _
"" & vbCr & _
"Regards" & Signature
.Attachments.Add "C:\Users\con04785\Desktop\Daily Protocol Status.pdf"
.Display 'Change to Send once you are happy this is working for you.
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub