Write From Outlook To Word 
Author Message
 Write From Outlook To Word

Hi,

I have two questions that I'm asking for help in resolving.  I'm using Word
2000 on Windows XP.

First, I am trying to write the subject, sender name and body of emails in a
specific subfolder to the active Word document.  The code below works quite
well except for a formatting problem. I am trying to bold and set the font
to size 16 only for each subject that gets written but I want the rest of
the text to not be bolded and size 12.  I want this to happen for each email
that gets written in succession in the Word document. What is happening is
everything is bolded and size 16.

Second, I seem to be having a problem with Word not always getting shut
down, presumably happening when an error occurs.  I'd appreciate any
comments or suggestions on why this would be occurring or how to resolve it.
When I ctrl-alt-delete to bring up the Windows Task Manager, I sometimes
find numerous instances of Word running.

Thanks for you help,

Ron Miller

Sub outlook_to_Word()
    Dim MyOLApp
    Dim CC As Document
    Dim MyNamespace
    Dim MyOutlookToday
    Dim MyInbox
    Dim MySubFolder
    Dim ItemNumber
    Dim objWordDoc
    Dim myrange As Range
    Set MyOLApp = CreateObject("Outlook.Application")
    Set MyNamespace = MyOLApp.GetNamespace("MAPI")
    Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
    Set MyInbox = MyOutlookToday.Folders("Inbox")
    Set MySubFolder = MyInbox.Folders("HoldItems")
    Set objdoc = CreateObject("Word.Application")
    ItemNumber = 0
    Set CC = ActiveDocument
    Set myrange = CC.Range(Start:=CC.Content.Start, End:=CC.Content.End)
    myrange.Bold = False
    myrange.Font.Size = 12
    Do
        ItemNumber = ItemNumber + 1
        Set myrange =
Documents(CC.Name).Range(Start:=Documents(CC.Name).Content.Start,

End:=Documents(CC.Name).Content.End)
        myrange.InsertAfter MySubFolder.Items(ItemNumber).Subject
        myrange.Bold = True
        myrange.Font.Size = 16
        CC.Range.InsertParagraphAfter
        myrange.SetRange Start:=Documents(CC.Name).Content.End,

End:=Documents(CC.Name).Content.End
        myrange.Bold = False
        myrange.Font.Size = 12
        myrange.InsertAfter MySubFolder.Items(ItemNumber).SenderName
        CC.Range.InsertParagraphAfter
        myrange.SetRange Start:=Documents(CC.Name).Content.End,

End:=Documents(CC.Name).Content.End
        myrange.Bold = False
        myrange.Font.Size = 12
        myrange.InsertAfter MySubFolder.Items(ItemNumber).Body
        CC.Range.InsertParagraphAfter
        myrange.InsertAfter

"=========================================================================="
        CC.Range.InsertParagraphAfter
        CC.Range.InsertParagraphAfter
        counter = counter + 1
    Loop Until ItemNumber = MySubFolder.Items.Count
    objdoc.Quit
End Sub



Fri, 15 Jul 2005 03:00:45 GMT  
 Write From Outlook To Word
I forgot to mention that I'm also using Outlook 2000.  Outlook is the
controlling document for the code below which is why I posted this to an
Outlook newsgroup and not a Word newsgroup.


Quote:
> Hi,

> I have two questions that I'm asking for help in resolving.  I'm using
Word
> 2000 on Windows XP.

> First, I am trying to write the subject, sender name and body of emails in
a
> specific subfolder to the active Word document.  The code below works
quite
> well except for a formatting problem. I am trying to bold and set the font
> to size 16 only for each subject that gets written but I want the rest of
> the text to not be bolded and size 12.  I want this to happen for each
email
> that gets written in succession in the Word document. What is happening is
> everything is bolded and size 16.

> Second, I seem to be having a problem with Word not always getting shut
> down, presumably happening when an error occurs.  I'd appreciate any
> comments or suggestions on why this would be occurring or how to resolve
it.
> When I ctrl-alt-delete to bring up the Windows Task Manager, I sometimes
> find numerous instances of Word running.

> Thanks for you help,

> Ron Miller

> Sub outlook_to_Word()
>     Dim MyOLApp
>     Dim CC As Document
>     Dim MyNamespace
>     Dim MyOutlookToday
>     Dim MyInbox
>     Dim MySubFolder
>     Dim ItemNumber
>     Dim objWordDoc
>     Dim myrange As Range
>     Set MyOLApp = CreateObject("Outlook.Application")
>     Set MyNamespace = MyOLApp.GetNamespace("MAPI")
>     Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
>     Set MyInbox = MyOutlookToday.Folders("Inbox")
>     Set MySubFolder = MyInbox.Folders("HoldItems")
>     Set objdoc = CreateObject("Word.Application")
>     ItemNumber = 0
>     Set CC = ActiveDocument
>     Set myrange = CC.Range(Start:=CC.Content.Start, End:=CC.Content.End)
>     myrange.Bold = False
>     myrange.Font.Size = 12
>     Do
>         ItemNumber = ItemNumber + 1
>         Set myrange =
> Documents(CC.Name).Range(Start:=Documents(CC.Name).Content.Start,

> End:=Documents(CC.Name).Content.End)
>         myrange.InsertAfter MySubFolder.Items(ItemNumber).Subject
>         myrange.Bold = True
>         myrange.Font.Size = 16
>         CC.Range.InsertParagraphAfter
>         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> End:=Documents(CC.Name).Content.End
>         myrange.Bold = False
>         myrange.Font.Size = 12
>         myrange.InsertAfter MySubFolder.Items(ItemNumber).SenderName
>         CC.Range.InsertParagraphAfter
>         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> End:=Documents(CC.Name).Content.End
>         myrange.Bold = False
>         myrange.Font.Size = 12
>         myrange.InsertAfter MySubFolder.Items(ItemNumber).Body
>         CC.Range.InsertParagraphAfter
>         myrange.InsertAfter

"=========================================================================="

- Show quoted text -

Quote:
>         CC.Range.InsertParagraphAfter
>         CC.Range.InsertParagraphAfter
>         counter = counter + 1
>     Loop Until ItemNumber = MySubFolder.Items.Count
>     objdoc.Quit
> End Sub



Fri, 15 Jul 2005 03:28:29 GMT  
 Write From Outlook To Word
Even though you are controlling Word from Outlook, your issue is with Word
VBA, specifically the Range object.  You should probably repost to the Word
newsgroup.

You might want to include 'Set objDoc = Nothing' at the end of your code;
that might prevent duplicate instances of WINWORD.EXE.

--
Eric Legault, MCSD
ADAPSYS - http://www.adapsys.ca


Quote:
> I forgot to mention that I'm also using Outlook 2000.  Outlook is the
> controlling document for the code below which is why I posted this to an
> Outlook newsgroup and not a Word newsgroup.



> > Hi,

> > I have two questions that I'm asking for help in resolving.  I'm using
> Word
> > 2000 on Windows XP.

> > First, I am trying to write the subject, sender name and body of emails
in
> a
> > specific subfolder to the active Word document.  The code below works
> quite
> > well except for a formatting problem. I am trying to bold and set the
font
> > to size 16 only for each subject that gets written but I want the rest
of
> > the text to not be bolded and size 12.  I want this to happen for each
> email
> > that gets written in succession in the Word document. What is happening
is
> > everything is bolded and size 16.

> > Second, I seem to be having a problem with Word not always getting shut
> > down, presumably happening when an error occurs.  I'd appreciate any
> > comments or suggestions on why this would be occurring or how to resolve
> it.
> > When I ctrl-alt-delete to bring up the Windows Task Manager, I sometimes
> > find numerous instances of Word running.

> > Thanks for you help,

> > Ron Miller

> > Sub outlook_to_Word()
> >     Dim MyOLApp
> >     Dim CC As Document
> >     Dim MyNamespace
> >     Dim MyOutlookToday
> >     Dim MyInbox
> >     Dim MySubFolder
> >     Dim ItemNumber
> >     Dim objWordDoc
> >     Dim myrange As Range
> >     Set MyOLApp = CreateObject("Outlook.Application")
> >     Set MyNamespace = MyOLApp.GetNamespace("MAPI")
> >     Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
> >     Set MyInbox = MyOutlookToday.Folders("Inbox")
> >     Set MySubFolder = MyInbox.Folders("HoldItems")
> >     Set objdoc = CreateObject("Word.Application")
> >     ItemNumber = 0
> >     Set CC = ActiveDocument
> >     Set myrange = CC.Range(Start:=CC.Content.Start, End:=CC.Content.End)
> >     myrange.Bold = False
> >     myrange.Font.Size = 12
> >     Do
> >         ItemNumber = ItemNumber + 1
> >         Set myrange =
> > Documents(CC.Name).Range(Start:=Documents(CC.Name).Content.Start,

> > End:=Documents(CC.Name).Content.End)
> >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Subject
> >         myrange.Bold = True
> >         myrange.Font.Size = 16
> >         CC.Range.InsertParagraphAfter
> >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > End:=Documents(CC.Name).Content.End
> >         myrange.Bold = False
> >         myrange.Font.Size = 12
> >         myrange.InsertAfter MySubFolder.Items(ItemNumber).SenderName
> >         CC.Range.InsertParagraphAfter
> >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > End:=Documents(CC.Name).Content.End
> >         myrange.Bold = False
> >         myrange.Font.Size = 12
> >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Body
> >         CC.Range.InsertParagraphAfter
> >         myrange.InsertAfter

"=========================================================================="

- Show quoted text -

Quote:
> >         CC.Range.InsertParagraphAfter
> >         CC.Range.InsertParagraphAfter
> >         counter = counter + 1
> >     Loop Until ItemNumber = MySubFolder.Items.Count
> >     objdoc.Quit
> > End Sub



Sat, 16 Jul 2005 05:25:04 GMT  
 Write From Outlook To Word
Thanks Eric,

Posting to the Word group is what I'll do.

Ron Miller


Quote:
> Even though you are controlling Word from Outlook, your issue is with Word
> VBA, specifically the Range object.  You should probably repost to the
Word
> newsgroup.

> You might want to include 'Set objDoc = Nothing' at the end of your code;
> that might prevent duplicate instances of WINWORD.EXE.

> --
> Eric Legault, MCSD
> ADAPSYS - http://www.adapsys.ca



> > I forgot to mention that I'm also using Outlook 2000.  Outlook is the
> > controlling document for the code below which is why I posted this to an
> > Outlook newsgroup and not a Word newsgroup.



> > > Hi,

> > > I have two questions that I'm asking for help in resolving.  I'm using
> > Word
> > > 2000 on Windows XP.

> > > First, I am trying to write the subject, sender name and body of
emails
> in
> > a
> > > specific subfolder to the active Word document.  The code below works
> > quite
> > > well except for a formatting problem. I am trying to bold and set the
> font
> > > to size 16 only for each subject that gets written but I want the rest
> of
> > > the text to not be bolded and size 12.  I want this to happen for each
> > email
> > > that gets written in succession in the Word document. What is
happening
> is
> > > everything is bolded and size 16.

> > > Second, I seem to be having a problem with Word not always getting
shut
> > > down, presumably happening when an error occurs.  I'd appreciate any
> > > comments or suggestions on why this would be occurring or how to
resolve
> > it.
> > > When I ctrl-alt-delete to bring up the Windows Task Manager, I
sometimes
> > > find numerous instances of Word running.

> > > Thanks for you help,

> > > Ron Miller

> > > Sub outlook_to_Word()
> > >     Dim MyOLApp
> > >     Dim CC As Document
> > >     Dim MyNamespace
> > >     Dim MyOutlookToday
> > >     Dim MyInbox
> > >     Dim MySubFolder
> > >     Dim ItemNumber
> > >     Dim objWordDoc
> > >     Dim myrange As Range
> > >     Set MyOLApp = CreateObject("Outlook.Application")
> > >     Set MyNamespace = MyOLApp.GetNamespace("MAPI")
> > >     Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
> > >     Set MyInbox = MyOutlookToday.Folders("Inbox")
> > >     Set MySubFolder = MyInbox.Folders("HoldItems")
> > >     Set objdoc = CreateObject("Word.Application")
> > >     ItemNumber = 0
> > >     Set CC = ActiveDocument
> > >     Set myrange = CC.Range(Start:=CC.Content.Start,

End:=CC.Content.End)

- Show quoted text -

Quote:
> > >     myrange.Bold = False
> > >     myrange.Font.Size = 12
> > >     Do
> > >         ItemNumber = ItemNumber + 1
> > >         Set myrange =
> > > Documents(CC.Name).Range(Start:=Documents(CC.Name).Content.Start,

> > > End:=Documents(CC.Name).Content.End)
> > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Subject
> > >         myrange.Bold = True
> > >         myrange.Font.Size = 16
> > >         CC.Range.InsertParagraphAfter
> > >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > > End:=Documents(CC.Name).Content.End
> > >         myrange.Bold = False
> > >         myrange.Font.Size = 12
> > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).SenderName
> > >         CC.Range.InsertParagraphAfter
> > >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > > End:=Documents(CC.Name).Content.End
> > >         myrange.Bold = False
> > >         myrange.Font.Size = 12
> > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Body
> > >         CC.Range.InsertParagraphAfter
> > >         myrange.InsertAfter

"=========================================================================="

- Show quoted text -

Quote:
> > >         CC.Range.InsertParagraphAfter
> > >         CC.Range.InsertParagraphAfter
> > >         counter = counter + 1
> > >     Loop Until ItemNumber = MySubFolder.Items.Count
> > >     objdoc.Quit
> > > End Sub



Sat, 16 Jul 2005 16:19:39 GMT  
 Write From Outlook To Word
As a followup to what I originally posted, with the help of the Word
newsgroup, I was able to get a good working code.

I've pasted the completed, working code below for anyone who is interested.
Note that for it to work you'll need a subfolder of your inbox named
"holditems".  Otherwise, you'll have to adjust the code for the folders of
your choice. This of course could be further adapted to using items selected
with the mouse in any folder, not just one. I only did it this way to
satisfy my immediate need.

Also, I was not able to solve the problem with additional instances of Word
remaining open.  To work around this, I substituted getObject for
createObject.  This works but requires Word to be open with the intended
active document already loaded.

Ron Miller

Sub outlook_to_Word()
    Dim MyOLApp
    Dim CC As Document
    Dim MyNamespace
    Dim MyOutlookToday
    Dim MyInbox
    Dim objDoc As Word.Application
    Dim MySubFolder
    Dim ItemNumber
    Dim objWordDoc
    Dim myRange As Range
    Set MyOLApp = CreateObject("Outlook.Application")
    Set MyNamespace = MyOLApp.GetNamespace("MAPI")
    Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
    Set MyInbox = MyOutlookToday.Folders("Inbox")
    Set MySubFolder = MyInbox.Folders("HoldItems")
    'Set objDoc = CreateObject("Word.Application")
    Set objDoc = GetObject(, "Word.Application")
    ItemNumber = 0
    Set CC = ActiveDocument
    Set myRange = Documents(CC.Name).Range
    'set range to end of doc
    myRange.Collapse wdCollpaseEnd
    Do
        ItemNumber = ItemNumber + 1
        myRange.Text = MySubFolder.Items(ItemNumber).Subject & vbCr
        'Format the range
        myRange.Bold = True
        myRange.Font.Size = 16
        myRange.Collapse wdCollapseEnd
        'proceed to the next set of text, all formatted the same
        myRange.Text = MySubFolder.Items(ItemNumber).SenderName & vbCr & _
            MySubFolder.Items(ItemNumber).Body & vbCr & vbCr & vbCr
        myRange.Bold = False
        myRange.Font.Size = 12
        myRange.Collapse wdCollapseEnd
        myRange.InsertBreak Type:=wdPageBreak
    Loop Until ItemNumber = MySubFolder.Items.Count
    'objDoc.Quit
    Set objDoc = Nothing
    Exit Sub
errorhandler:
    MsgBox "An error occurred"
    'objDoc.Quit
    Set objDoc = Nothing
End Sub


Quote:
> Thanks Eric,

> Posting to the Word group is what I'll do.

> Ron Miller



> > Even though you are controlling Word from Outlook, your issue is with
Word
> > VBA, specifically the Range object.  You should probably repost to the
> Word
> > newsgroup.

> > You might want to include 'Set objDoc = Nothing' at the end of your
code;
> > that might prevent duplicate instances of WINWORD.EXE.

> > --
> > Eric Legault, MCSD
> > ADAPSYS - http://www.adapsys.ca



> > > I forgot to mention that I'm also using Outlook 2000.  Outlook is the
> > > controlling document for the code below which is why I posted this to
an
> > > Outlook newsgroup and not a Word newsgroup.



> > > > Hi,

> > > > I have two questions that I'm asking for help in resolving.  I'm
using
> > > Word
> > > > 2000 on Windows XP.

> > > > First, I am trying to write the subject, sender name and body of
> emails
> > in
> > > a
> > > > specific subfolder to the active Word document.  The code below
works
> > > quite
> > > > well except for a formatting problem. I am trying to bold and set
the
> > font
> > > > to size 16 only for each subject that gets written but I want the
rest
> > of
> > > > the text to not be bolded and size 12.  I want this to happen for
each
> > > email
> > > > that gets written in succession in the Word document. What is
> happening
> > is
> > > > everything is bolded and size 16.

> > > > Second, I seem to be having a problem with Word not always getting
> shut
> > > > down, presumably happening when an error occurs.  I'd appreciate any
> > > > comments or suggestions on why this would be occurring or how to
> resolve
> > > it.
> > > > When I ctrl-alt-delete to bring up the Windows Task Manager, I
> sometimes
> > > > find numerous instances of Word running.

> > > > Thanks for you help,

> > > > Ron Miller

> > > > Sub outlook_to_Word()
> > > >     Dim MyOLApp
> > > >     Dim CC As Document
> > > >     Dim MyNamespace
> > > >     Dim MyOutlookToday
> > > >     Dim MyInbox
> > > >     Dim MySubFolder
> > > >     Dim ItemNumber
> > > >     Dim objWordDoc
> > > >     Dim myrange As Range
> > > >     Set MyOLApp = CreateObject("Outlook.Application")
> > > >     Set MyNamespace = MyOLApp.GetNamespace("MAPI")
> > > >     Set MyOutlookToday = MyNamespace.Folders("Personal Folders")
> > > >     Set MyInbox = MyOutlookToday.Folders("Inbox")
> > > >     Set MySubFolder = MyInbox.Folders("HoldItems")
> > > >     Set objdoc = CreateObject("Word.Application")
> > > >     ItemNumber = 0
> > > >     Set CC = ActiveDocument
> > > >     Set myrange = CC.Range(Start:=CC.Content.Start,
> End:=CC.Content.End)
> > > >     myrange.Bold = False
> > > >     myrange.Font.Size = 12
> > > >     Do
> > > >         ItemNumber = ItemNumber + 1
> > > >         Set myrange =
> > > > Documents(CC.Name).Range(Start:=Documents(CC.Name).Content.Start,

> > > > End:=Documents(CC.Name).Content.End)
> > > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Subject
> > > >         myrange.Bold = True
> > > >         myrange.Font.Size = 16
> > > >         CC.Range.InsertParagraphAfter
> > > >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > > > End:=Documents(CC.Name).Content.End
> > > >         myrange.Bold = False
> > > >         myrange.Font.Size = 12
> > > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).SenderName
> > > >         CC.Range.InsertParagraphAfter
> > > >         myrange.SetRange Start:=Documents(CC.Name).Content.End,

> > > > End:=Documents(CC.Name).Content.End
> > > >         myrange.Bold = False
> > > >         myrange.Font.Size = 12
> > > >         myrange.InsertAfter MySubFolder.Items(ItemNumber).Body
> > > >         CC.Range.InsertParagraphAfter
> > > >         myrange.InsertAfter

"=========================================================================="

- Show quoted text -

Quote:
> > > >         CC.Range.InsertParagraphAfter
> > > >         CC.Range.InsertParagraphAfter
> > > >         counter = counter + 1
> > > >     Loop Until ItemNumber = MySubFolder.Items.Count
> > > >     objdoc.Quit
> > > > End Sub



Mon, 18 Jul 2005 19:43:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Outlook Contacts written into a Word document

2. Write contents of Outlook message to Access record

3. Outlook Macro - write text

4. How to write to registry with outlook code

5. Write HTML-Code in Outlook MailItem

6. how to write a program to get personal address book and calendar from outlook

7. Writing Outlook extensions in VB5(?)

8. Attn VB Programmers writing for Outlook 2000

9. VB Programmers writing for Outlook 2000

10. Writing Code to Transfer from Access Table to Outlook

11. ?? Programatically read/write Outlook options?

12. Write VBA macros in Outlook Express 4/5 ?

 

 
Powered by phpBB® Forum Software