Code that gives unexpected result

D

Dave Neve

Hi

Both the following codes produce a
MsgBox with the word 'ok' but I was expecting a date and an adress.

What is wrong please?

Sub DateOfLetter()
MsgBox ActiveDocument.GetLetterContent.DateFormat
End Sub

Sub RecipientOfLetter()
Dim MyLetterContent
Set MyLetterContent = ActiveDocument.GetLetterContent
MsgBox MyLetterContent.RecipientName
End Sub
 
A

Alex Ivanov

Obviously, your ActiveDocument does not have any LetterContent set. Perhaps
you are using wrong object...

Sub test()
Dim myletter As LetterContent
Set myletter = New LetterContent
With myletter
.DateFormat = Date
.RecipientName = "Nobody There"
.RecipientAddress = "100 Main St." & vbCr & "Bellevue, WA 98004"
.AttentionLine = "Read this"
.Subject = "Help me"
End With
ActiveDocument.SetLetterContent myletter
DateOfLetter ' Now it should work
RecipientOfLetter
'Documents.Add.RunLetterWizard LetterContent:=myletter, WizardMode:=True
End Sub
 
D

Dave Neve

Thanks Alex.

I finally got it to work cos it took me ages to know what do do with it
exactly.

And it's been very useful looking at it. I didn't even know you could invoke
other subs just by typing their names (I tried to put them together at first
under one sub)

Cheers
 

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