Originally Posted by
June7
Why doesn't work - error message, wrong results, nothing happens? Post code and/or attach project for analysis.
To clarify, I haven't got any Access 2010 code to show. I was using the below code in Excel 2003 but, in researching, found that this won't work in Access 2010. It works perfect in Excel 2003. Also, to be fair, the code is not my personal work but primarly an example I found googling a few years ago.
I guess my question would be more accurate as: How do I do the below in Access 2010? I can figure out how to create an html file but this part seems to escape me.
Thanks
Excel VBA code:
Code:
Sub email()
Dim FSO As Object
Dim HTMLcode As String
Dim HTMLfile As Object
Dim myOlApp As Object
Dim myOlMail As Object
' Read all data from the TempFile which now in HTML
Set FSO = CreateObject("Scripting.FileSystemObject")
Set HTMLfile = FSO.GetFile(sFNmht).OpenAsTextStream(1, -2)
HTMLcode = HTMLfile.ReadAll
HTMLfile.Close
HTMLcode = Replace(HTMLcode, "align=center x:publishsource=", _
"align=left x:publishsource=")
' Start Outlook
Set myOlApp = CreateObject("Outlook.Application")
' Create the mail item and send it.
Set myOlMail = myOlApp.CreateItem(0)
With myOlMail
.To = "DL-team; DL-SRT"
.Subject = "Paramedic Telemetry DSEL for " & Format(Sheets("TSEL").Range("B2"), "dd-mmm-yyyy")
.HTMLBody = HTMLcode
.Send
End With
' Cleanup and Release Objects from memory
Set myOlMail = Nothing
Set myOlApp = Nothing
Set HTMLfile = Nothing
Set FSO = Nothing
End Sub