Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

How can print all mails in a folder without any space wastage.

Hi,
How can print all mails in a folder without any space wastage.
All set to one size and get them all one after the other in the least blank spaces.

REgards
Sharath
0
bsharath
Asked:
bsharath
  • 2
1 Solution
 
Dave BrettVice President - Business EvaluationCommented:
this version uses a regex to strip out all blank rows
Cheers
Dave

Option Explicit
 
Sub PrintMe()
    Dim ns As Outlook.NameSpace, oFolder As Outlook.MAPIFolder, targetFolderItems, oMessage As MailItem
    Dim MyFile As String
 
    Set ns = Application.GetNamespace("MAPI")
    Set oFolder = ns.PickFolder
    Set targetFolderItems = oFolder.Items
    MyFile = "C:\MyFile.txt"
 
    Open MyFile For Output As #1
    For Each oMessage In targetFolderItems
        Print #1, oMessage.SentOn
        Print #1, KillBlanks(oMessage)
        Print #1, String(100, "*")
        Print #1, vbNewLine
    Next oMessage
    Close #1
 
    UseWdAgain (MyFile)
 
End Sub
Sub UseWdAgain(sTextFile As String)
    Dim WdApp As Object
 
    Set WdApp = CreateObject("Word.Application")
    WdApp.Visible = False
    WdApp.ScreenUpdating = True
 
    WdApp.documents.Open FileName:="C:\MyFile.txt"
    WdApp.Selection.WholeStory
 
    WdApp.Selection.Font.Size = 9
    WdApp.PrintOut
 
    WdApp.documents.Close
    WdApp.Quit
    Set WdApp = Nothing
End Sub
 
Function KillBlanks(ByVal oMessage) As String
    Dim regex, RegM, tempstr As String
    Set regex = CreateObject("vbscript.regexp")
    With regex
        .Global = True
        .multiline = True
        .Pattern = "[\n\r]"
        tempstr = .Replace(oMessage.Body, "@@")
        .Pattern = "@@(@@)*"
        KillBlanks = .Replace(tempstr, Chr(10))
    End With
End Function

Open in new window

0
 
bsharathAuthor Commented:
Thank U..... Worked perfect
0
 
Dave BrettVice President - Business EvaluationCommented:
thx Sharath :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now