Help in programmatically setting formatting in an AppointmentItem

  • Thread starter Thread starter Nilay
  • Start date Start date
N

Nilay

Hi,
i have created a macro to generate some meeting invites.
I used the WordEditor to set some formatting (Bold on/off, hyperlinks etc).

However, i find that the formatting works only partially (or not at all). so
far i've noticed that only the first invite generated is perfectly formatted.

Can anyone help me out with this? Do i need to add something to the code or
set some objects to null to ensure that the formatting stays throughout my
outlook session?
 
More info, please: Outlook version, relevant code snippet, more explanation
of what you mean by "the first invite."
 
I'm using Outlook 2007.

The code for the part where i'm using the WordEditor is something like this.
I havent used this before so I'm not sure what I'm doing wrong.

Dim wrdDoc as Word.Document
Dim wrdSel as Word.Selection 'etc etc

With olInvite
.Start = ' etc etc
If olInvite.GetInspector.EditorType = olEditorWord Then
Set wrdDoc = olInvite.GetInspector.WordEditor
Set wrdSel = wrdDoc.Windows(1).Selection

wrdSel.TypeText text:="text" ' i notice that if i try to change
something to bold in the middle of a line it doesnt work. but it works if the
text is on a new line.
wrdSel.Font.Bold = wdToggle
wrdSel.TypeText text:="text"

wrdSel.TypeText "some text"
wrdSel.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
wrdDoc.Hyperlinks.Add wrdSel.Range, "http://www.somelink.com" 'the
hyperlink with the "some text" seems to work only the first time (see below),
for all subsequent invites i get the hyperlink but no text displayed (just
blank).

End If
.Display
End With
Set wrdDoc = nothing
Set wrdSel = Nothing
set olInvite = nothing

Note: I got the code by recording a macro on MS Word and then modifying it.

By "first invite" i mean the invite that is generated when i use the macro
for the first time after i start outlook. all subsequent invites created by
using that macro partially lose the formatting, unless i actually restart
outlook.

I hope you can help me out, i've never worked with VBA in such depth before.
 
How formatting is applied depends in part on what the current Word.Selection
object encompasses. You should see similar effects when you're working
manually in a document. As you already seem to know a bit about how to move
the selection, I suggest you continue playing with that, using the Word
macro recorder as needed, to nail down the exact effect you want.

What do you mean by "partially lose formatting"?

I can't think of any reason why one meeting request created with the same
code would be any different from another.
 
Back
Top