Accessing Fields on an Outlook Template from Word

G

GrannyM

I'm using Word and Outlook 2000. Please let me know if I should be posting
this to the Outlook discussion group instead of here.

I have a simple function that I use to send an email from Word. In the
version I have below, it uses an Outlook template and it works just great.
But now they've decided they want to add some textboxes to the Outlook
template that need to be filled in by the macro before it sends the template.
I have programmed in Word, Excel and Access, but never in Outlook. I have
spent several days researching Word references and Outlook references and
have not been able to figure out how to fill in the textboxes on the Outlook
template before sending it. Since the textboxes are named (in this case
"txtPlanName" for one), it seems like it should be doable. From my research,
it looks possible, but everything I've tried hasn't worked.

Here is my basic code without trying to fill in the textboxes:
Function SendEmail(eeEmail$, EmailSubject$, SendNow As Boolean)
'create email with attachment

Dim OlApp As Outlook.Application
Dim SafeItem As Object
Dim oItem As Object
Dim utils As Object
Dim nspnamespace As Outlook.NameSpace

Set OlApp = Outlook.Application
Set nspnamespace = OlApp.GetNamespace("Mapi")
Set SafeItem = CreateObject("SafeOutlook.SafeMailItem")
Set oItem = OlApp.CreateItemFromTemplate("f:\winword\template\test.oft")
Set utils = CreateObject("cpioutlook.MAPIUtils")

SafeItem.Item = oItem
SafeItem.Recipients.Add eeEmail$
SafeItem.Recipients.ResolveAll
SafeItem.Subject = EmailSubject$

if SendNow = True then
SafeItem.Send
else
SafeItem.Display
end if

Set OlApp = Nothing
Set nspnamespace = Nothing
Set SafeItem = Nothing
Set oItem = Nothing

End Function

Thanks, any help is appreciated.
 
P

Peter Jamieson

AFAICR you use something like

SafeItem.UserProperties("your field name")

but it has been a while...
 

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