How do I paste Clipboard contents using macro?

G

Guest

In Outlook 2002, I need a macro to insert some standard text into a new mail
message then paste the contents of the clipboard in Courier New font (to
maintain the format) below that text. With the following code I am able to
do everything except format the clipboard contents using the Courier New
font. Since I'm using Word as my editor, I created a macro in Word to search
for the first phrase in the clipboard text, then select the text and change
the font that way. That works, but my boss wants one macro in Outlook that
will accomplish everything.

Even if the whole body of the message (standard and clipboard text) is in
Courier New font, that would be fine. We don't want all messages to use that
font though.

Does anyone have any ideas how I can do that?

Public Sub ItineraryApproval()

Dim MyItem As MailItem
Dim sTempString As String

On Error Resume Next

Load TempFormForClipboard

Set MyItem = Application.CreateItem(0)

sTempString = "****NOTICE, PLEASE RESPOND ASAP****" & vbCrLf & vbCrLf &
vbCrLf
sTempString = sTempString & "Your name spelling must be same as picture
I.D. Ticketing is required 24 hours after reservations are made. Please
review the itinerary and return it signed." & vbCrLf & vbCrLf
sTempString = sTempString & "SIGNATURE________________________________"
& vbCrLf & vbCrLf
sTempString = sTempString & vbCrLf & vbCrLf & vbCrLf & MyData.GetText(1)

MyItem.Body = sTempString
MyItem.Display

Unload TempFormForClipboard

End Sub
 
M

Michael Bauer

Am Fri, 17 Feb 2006 08:42:19 -0800 schrieb Maureen:

Maureen, if Word is the mail editor then the Inspector´s WordEditor property
is a reference on the Word.Document object. You could add a reference on the
Word library via Tools/References to your Outlook project and use that
Document object like you´d do in a Word macro.
 
G

Guest

Well, I'm lost. I think Inspector must be part of VB and since I'm learning
by seeing patterns in other code, I haven't run into that one yet. I found
Tools/Reference in Outlook VB and checked the box for MS Word 10.0 Object
Library, but I'm not sure what to do next.

I'll keep reading and trying to make sense of it and will appreciate any
additional help you can give.

Thank you!
 
M

Michael Bauer

Am Mon, 20 Feb 2006 15:14:26 -0800 schrieb Maureen:

Maureen, you told us to have a script that runs fine in Word (but we don´t
see or know that code).

In Word you have a Document object which you´re using for sure. The same
object you can use in Outlook if Word is the mail editor. Sample:

Dim wd as Word.Document
Set wd=Application.ActiveInspector.WordEditor

Via the wd variable in Outlook you have now the same access to all the
Document´s properties like you would have in Word.

I think you can´t format the clipboard content itself. Instead you need to
insert it into the Word Document first, then set the proper Range object and
use the Range´s Font property.

Sample for formatting all the Document:
wd.Range.Font.Name = "courier new"
 
R

Russ

This is surprisingly hard... why don't they have a "record macro" feature in
Outlook as they do in Word?

No matter. One easy way to record macros and then use them in Outlook,
avoiding a very costly macro programming learning curve, is to record them
in Word, then set Outlook to edit e-mail using the Word editor. Now, all
your Word macros (the ones saved in in Normal.dot) will be available when
composing e-mail.

To set Outlook 2003 to use Word as its editor, go to Tools, Options, then
Mail Format tab, click the checkbox that says "Use Microsoft Word 2003 to
Edit E-mail Messages", and Apply.

To record your macro, you can open a new e-mail message which will bring up
the Word editor, then use Tools, Macros, Record New Macro just like in Word.
If you are a VB bithead, you can still edit the macro in VB and apply
whatever customizations you need to the code. At least you're starting with
some stock code, rather than from scratch.

Now, "all your text are belong to Word." By doing this, I have a dropdown
that allows me to easily switch to an all-text format, so that should be
okay. I'm not sure of the security implications of using Word to compose
e-mail messages; I suppose if I have a macro virus in Word, I might be able
to spread it. Caveat emptor.

Hope this helps.
 
G

Guest

I'm back with another question. I followed your suggestion, and it works
beautifully. The problem is that we had links in the Word form, so I had to
change the Outlook format to HTML in addition to using Word as the editor.
Now some of the email we receive daily that needs to be forwarded to our
clients takes forever to open in Word. If I change the mailformat to RTF,
forwarding those messages is no problem but the links don't work. Do you
know of a way to make the links work in RTF?
 
G

Guest

Please disregard my last question. I forgot that using Word as the email
editor is the problem, not HTML vs. RTF.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top