Macro code for default subject line button

G

Guest

Hi there,

I'm after maco code for a default subject line button. When button is
clicked the subject displays my required subject.

Thanks in advanced.

Steve
 
G

Guest

Steve:

I'm assuming you have a situation like always writing memos or reports with
the same value for Subject (a built-in document property). This code will
change the current document's Subject property.

ActiveDocument.BuiltInDocumentProperties.Item("Subject") = "Default Subject
Text"

You still have to deal with having a reference to this property correctly
inserted as a field in the document.

You could create templates with a macrobutton in them that launches this
macro.

You could create a custom toolbar button and add it to an existing toolbar,
or create a custom toolbar. If you do, make sure you save that customization
in the template that contains the macro, so the button is only available when
it can be used.

Bear
 
G

Guest

Steve:

And don't overlook the AUTOTEXTLIST field. You right-click this and select
from among autotext entries stored with the template. Example:

{ AUTOTEXTLIST \s "SteveSubject" \t "Right-click to select a subject." \*
MERGEFORMAT }

Bear
 
G

Guest

Having problems here fellas.

Just to confirm, i'm running outlook 2007 which i assume creating assigned
buttons is the same as word. Not sure wether the autotext entries are
available.

In a new email window i've created a button on the quick access tab with the
following code "Sub subject()
ActiveDocument.BuiltInDocumentProperties.Item("Subject") = "Your Requested
quotation is attached."End Sub"

This is now failing.

I will require possibly four buttons each with a diferent subjects.

Is this the best way of doing it?

Steve
 
C

CyberTaz

A macro really isn't necessary - in Word 2007 take a look in Help under
QuickParts and Building Blocks, in earlier versions look up AutoText.
 
C

CyberTaz

Sorry - since you posted to a Word group & didn't mention otherwise I
assumed you were using Word. As I don't use Outlook I'm afraid I can't help.
 
G

Graham Mayor

If you add the Outlook object library to Word's vba references, something
like

Sub Send_As_Mail_Attachment()

' send the document as an attachment _
in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

'Prompt the user to save the document
ActiveDocument.Save

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed)"
'Set the recipient for a copy
.BCC = "(e-mail address removed)"
.Subject = "This is the subject"
'Add the document as an attachment, you can use the _
.displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, DisplayName:="Document as attachment"
.Display
End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

will work. Remove the bits you don't need.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

To anyone interested, the following code works a treat.

Sub MySubject()
Dim itm as Object
On Error Resume Next
Set itm = Application.ActiveInspector.CurrentItem
itm.Subject = "My Subject"
set itm = Nothing
End Sub
 

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