RIAS
asked on
Print .msg files with attachments vb6.0
Hi,
I need to set a printer which is different from default printer how do i set it and get the .msg file printed with all its attachments in vb 6.0
I need to set a printer which is different from default printer how do i set it and get the .msg file printed with all its attachments in vb 6.0
ASKER
Cheers mate will try and get back
ASKER
Hi,
In the link above where you set the folder the code shows the default outlook folder not sure how to use a different folder where my outlook files are located.
Set oFldr = oNs.GetDefaultFolder(olFol derInbox)
Cheers
In the link above where you set the folder the code shows the default outlook folder not sure how to use a different folder where my outlook files are located.
Set oFldr = oNs.GetDefaultFolder(olFol
Cheers
This code will find any folder in outlook.
Dim n As Outlook.NameSpace
Dim Incoming As Outlook.MAPIFolder
Set n = o.GetNamespace("MAPI")
Set Incoming = FindFolder(n.Folders, "\\Public Folders\All Public Folders\YourFolderName")
Function FindFolder(TopFolder As Outlook.Folders, TargetPath As String) As Outlook.MAPIFolder
Dim TempFolder As Outlook.MAPIFolder
Dim TempFolder2 As Outlook.MAPIFolder
For Each TempFolder In TopFolder
If TempFolder.FolderPath = TargetPath Then
Set FindFolder = TempFolder
Exit Function
Else 'walk through this folder too
Set TempFolder2 = FindFolder(TempFolder.Folders, TargetPath)
If Not TempFolder2 Is Nothing Then
Set FindFolder = TempFolder2
Exit Function
End If
End If
Next
End Function
ASKER
Cheers mate will try and get back
ASKER
Hi,
Is this syntax correct?
Set Incoming = FindFolder(oOutlook.Folder s, "C:\testing")
Cheers
Is this syntax correct?
Set Incoming = FindFolder(oOutlook.Folder
Cheers
ASKER
Actually i don't want to loo[p throught the folder as i have individual .msg files on my C drive any suggestions on this on how to print them with attachments
Cheers
Cheers
No, "C:\testing" is a file system folder, not an outlook folder name which are like "\\Mailbox - John Price\Sent Items". I thought you meant outlook folders.
If you have already saved the emails as .msg files, you need a different approach using regular file system searching for the .msg files and then create an MailItem from the .msg file. The only ways I know of to create an Outlook.MailItem from a .msg file is to either use outlook.CreateItemFromTemp late which actually creates a reply to the .msg (and thus may not get you what you need) or use outlook.CopyFile(filename, foldername ) to copy the .msg file to an outlook folder, whereupon you can open the mailitem in the usual way. I'll see if I can dredge up some code. Also some code for scanning folders.
If you have already saved the emails as .msg files, you need a different approach using regular file system searching for the .msg files and then create an MailItem from the .msg file. The only ways I know of to create an Outlook.MailItem from a .msg file is to either use outlook.CreateItemFromTemp
Let me back up a minute, you have .msg files. You want to print these with attachments. Printing the file is trivial, you don't need to deal with outlook at all, just do outlook.exe /p "msgfilename" as shown. I added the code to change the default printer.
What are the attachments?
What are the attachments?
' Windows API Declarations
Private Declare Function GetProfileString Lib "Kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Private Declare Function WriteProfileString Lib "Kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Sub cmdView_Click()
Dim PrevPrinter As String
PrevPrinter = GetDefaultPrinter
SetDefaultPrinter "\\DELLSERVER\HP LaserJet 8150 PCL 6,winspool,Ne06:"
Shell "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE /p ""C:\Projects\OutlookTestingVB6\test.msg"""
SetDefaultPrinter PrevPrinter
End Sub
Private Function SetDefaultPrinter(PrinterName_DriverName_PrinterPort As String) As Boolean
WriteProfileString "windows", "device", PrinterName_DriverName_PrinterPort
SetDefaultPrinter = CBool(SendMessageByString(&HFFFF&, &H1A, 0&, "windows"))
End Function
Private Function GetDefaultPrinter() As String
GetDefaultPrinter = Space$(1024)
GetDefaultPrinter = Trim$(Left$(GetDefaultPrinter, GetProfileString("windows", "device", "", GetDefaultPrinter, 1024)))
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great will try and be back...attachments are any type example: pdf,doc etc...you are really helping me...cheers mate
ASKER
Will try in office tomm..again cheers
>>attachments are any type example: pdf,doc
The ShellExecute will print any type of document as long as you can print it from your machine. it is the same as if you were to right-click on it and choose "Print". It opens the associated application and asks it to print to the default printer.
The ShellExecute will print any type of document as long as you can print it from your machine. it is the same as if you were to right-click on it and choose "Print". It opens the associated application and asks it to print to the default printer.
ASKER
Hi,
Tried your solution it does a great job for attachments but doesnt print the mail body.
msg.PrintOut----retrieves permission but doesnt print the body.Any suggestions
Cheers
Tried your solution it does a great job for attachments but doesnt print the mail body.
msg.PrintOut----retrieves permission but doesnt print the body.Any suggestions
Cheers
instead of mail.Printout, use the same ShellExecute, e.g.
ShellExecute 0, "print", "C:\Projects\OutlookTestingVB6\test2.msg", 0, 0, 0
ASKER
Cheers mate will try and get back
ASKER
You made my life simple
Cheers mate
Cheers mate
ASKER
Excellent solution given.Perfect in all respects.Easy to understand and implement.
Extremely helpful and patient mentor.
Extremely helpful and patient mentor.
http://www.freevbcode.com/ShowCode.asp?ID=4837
use printer.print instead of debug.print in the code. for changing default printer see this link
http://bytes.com/topic/access/answers/821821-changing-default-printer-using-vb-code-access