Creating text macro for mail

G

Guest

Would someone explain to me in "simple English" how to create a text macro
for email messages using VBA. The help files are useless. I get as far as
putting the code in. Then that's it. Macro will not run and comes back with
error message "424" object required.
Life was so much easier with 2003!!!!!
 
S

Sue Mosher [MVP-Outlook]

What do you mean by "a text macro for email messages" ? Please show the code you already have, to save us the trouble of going over what you already know, and indicate where the error occurs. What was easier in 2003 that you're now trying to accomplish in 2007? Is that what you have? You didn't say explicitly.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
G

Guest

It was easier to create a text macro for a mail message in 2003 because you
just used "record a macro" in word!!!!!
Here's the code;

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Font.Name = "Comic Sans MS"
Selection.Font.Italic = wdToggle
Selection.TypeText Text:="Hi,"
Selection.TypeParagraph
Selection.TypeText Text:= _
"Thanks for purchase and prompt payment. Will mail Tuesday an"
Selection.TypeText Text:="d it should take around 4 to 7 working days."
Selection.TypeParagraph
Selection.TypeText Text:="Regards"
Selection.TypeParagraph
Selection.TypeText Text:="Steve"
End Sub
 
S

Sue Mosher [MVP-Outlook]

It would have been nice if you'd actually answered the questions directly rather than having us read between the lines of your code to find out that what you want to do is create a VBA macro in Outlook that can insert text into the body of a mail message. In any case, the piece that's not obvious is the starting point, the actual code to get the Selection object. That looks like this:

Sub InsertText()
Dim objDoc as Word.Document
DIm objSel as Word.Selection
Set objDoc = Application.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.TypeText Text:="Hi,"
End Sub

In other words, the objSel object above works the same as the Selection object in your code snippet. Don't forget to add a reference to the Microsoft Word library to your Outlook VBA project.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
G

Guest

Thanks for reply but it would have been rather more "congenial" without the
"snide" remarks....Perhaps if you came down off your pedestal now and again
to rub shoulders with the less knowledgeable, your tone might be a bit less
"school teacherish" but I doubt it!
 
S

Sue Mosher [MVP-Outlook]

So, suggestions on how you can get faster, more focused responses to your posts are not useful information? Well, so be it.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
S

Sue Mosher [MVP-Outlook]

Could you please show us the code you're currently using and indicate which statement raises the error? The key issue is that your calls to Selection object properties and methods need to take place against a Selection object returned from the currently open Outlook item, as in the example I gave.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
G

Guest

The line "Selection.TypeText Text:="Hi," seems to be causing the problem. ( I
hope)


Sub Sale()
'
' Sale Macro
'
'
Selection.TypeText Text:="Hi,"
Selection.TypeParagraph
Selection.TypeText Text:= _
"Thanks for purchase and prompt payment. Will mail Tuesday an"
Selection.TypeText Text:= _
"d leave favourable feedback. Should take around 4 to 7 worki"
Selection.TypeText Text:="ng days."
Selection.TypeParagraph
Selection.TypeText Text:="Regards"
Selection.TypeParagraph
Selection.TypeText Text:="Steve."

End Sub
 
S

Sue Mosher [MVP-Outlook]

You need to derive a Word.Selection object from the actual open message. Here's the example again:

Sub InsertText()
Dim objDoc as Word.Document
DIm objSel as Word.Selection
Set objDoc = Application.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.TypeText Text:="Hi,"
End Sub

See how the last statement corresponds to the first TypeText statement in your code?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 

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