PDA

View Full Version : autoprint e-mail subject and body only



slhfire
09-24-2011, 10:23 AM
Good morning, afternoon, or evening as the case may be.

I am brand new to VBA because of not knowing what a great tool it can be. I have started learning today on how to perform certain tasks, but need some guidance on how to perform the following in Outlook.

- Automatically print a an e-mail or RSS subject and body only to the default printer.
- The printout needs to be in raw data format and in a single line. I also have to input a constant string "<ID01><PA>" to be specific prior to the printed line.
- Delete the E-mail or RSS once it has been printed.

This process is to run a LED signboard in our fire station. The goal is to have the e-mail received, stripped of all the un-necessary junk, then spit out to the signboard to display the nature and location of the incident. (The subject and body respectively).

The problem lies in that the signboard has to receive the command in the format "<ID01><PA>"insert message data here"

Any help would be immensely appreciated. In the meantime, I'll be reading up and writing what I'm sure will be a lot of bad code.

Thank You

slhfire
09-24-2011, 12:35 PM
So far I'm able to manually output to the signboard using a third part "raw data printer" so if I put the code into the VB and run it, I get what I need... just now need to add the message extraction and such to input where it needs to go.


Sub signprint()

Dim RDP as New RawDataPrinter.Printer
RetVal = RDP.PrintRawData("<ID01><PA><CB><FB>test<FP>")

End Sub


That just scrolls the word "test" across the screen.. disregard all the "<>" items as they are just operators that control how the sign displays the message.

slhfire
09-24-2011, 09:55 PM
After a re-evaluation of what I needed to do, and realizing that RSS is handled differently than mail. I had to make some changes, and I think I'm almost where I need to be... What I have now prints the selected RSS in the manner I need (for the most part). What I need now is for it to be constantly "watching" the RSS folder, and performing the print function when it finds the item as outlined in the subject field.

This is what I have so far


Sub ProcessRSS()

Dim objOL As Outlook.Application
Dim objList As Object
Dim RDP As New RawDataPrinter.Printer
RDP.Key = D8EC8EDCCB61CEFF26FBBDBA703760EFEC88FAAA3457DB7EDBE09E376005DAFD5755ED9B9BB 5743302CD050
Dim objItem As Object
Dim obsel As Outlook.Selection

Set objOL = CreateObject("Outlook.Application")
Set objsel = objOL.ActiveExplorer.Selection

For Each objItem In objsel
If (InStr(objItem.subject, "NJ") > 0) Then
RetVal = RDP.PrintRawData("<ID01><PA><CB><FB>" & vbCrLf & objItem.subject & vbCrLf & "msg body here" & "<FP>", , , , , , True)
End If
Next

End Sub


And additions or improvements would be appreciated.

Thanks for all the help you've already given me with previous posts.

JP2112
09-27-2011, 11:19 AM
Try this, however you will need to "point" it at your RSS folder. This is event code so after pasting and editing it, you will need to restart Outlook. See http://www.codeforexcelandoutlook.com/outlook-vba/where-do-i-put-my-outlook-vba-code/ for placement assistance.


Private WithEvents Items As Outlook.Items
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
Function GetItems(olNS As Outlook.NameSpace, folder As OlDefaultFolders) As Outlook.Items
Set GetItems = olNS.GetDefaultFolder(folder).Items
End Function
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
Set Items = GetItems(GetNS(olApp), olFolderInbox)
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim msg As Outlook.mailItem
Dim RDP As RawDataPrinter.Printer

If TypeName(item) = "MailItem" Then ' it's an email
Set msg = item

If (InStr(msg.Subject, "NJ") > 0) Then
Set RDP = CreateObject("RawDataPrinter.Printer")
RDP.Key = D8EC8EDCCB61CEFF26FBBDBA703760EFEC88FAAA3457DB7EDBE09E376005DAFD5755ED9B9BB 5743302CD050

RetVal = RDP.PrintRawData("<ID01><PA><CB><FB>" & vbCrLf & msg.Subject & vbCrLf & msg.Body & "<FP>", , , , , , True)
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub