runtime error 509:

L

Lorinda

I'm getting this error 509 with nothing after the colon. Then below it says
this command is not available. When I debug, It goes to the end of my
section (running a macro to do mail labels)
Selection.TypeParagraph
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""visit"""
WordBasic.MailMergePropagateLabel
WordBasic.MailMergePropagateLabel

Can anyone help? I'm using MS Word 2002 sp3
 
W

Wibs

Error 509 can occur when attempting to run a macro on a protected
document. Check the document's security settings.

Regards

Wibs
 
L

Lorinda

Hi, this document isn't protected. I can run the macro fine up to the point
of merging the label structure with the actual file of data, which is a word
file.
thank you!
 
D

Doug Robbins - Word MVP

When I run that code, I get the following after the 509

"The MailMergePropogateLabel command is not available because the document
is not a mail merge main document."

If I run it on a document that is a mailmerge label type main document, it
runs fine.

I have never found the need however to use vba to create mailmerge main
documents.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Lorinda

Hi Doug, thanks. Well, I'm not actually using vba to create it. Here's the
story:
I can use the mail merge function just fine when I do it manually. When I
try to create a MACRO, to perform the whole process for me, it hangs up with
that 509 error, and there is a Debug option on the error window, that when I
choose it, takes me to the vb window where that statement is hilited yellow.

The merge works fine on its own. It's just after I record doing it in a
macro, and then run the macro, it does the above. ??? It's to make labels
for files of our discharged hospital patients and the users having to do the
mail merge manually isn't going to last very long... I don't know what else
to try...

Any help is so appreciated!!! :) Hope you all are having a good holiday out
there~
 
D

Doug Robbins - Word MVP

What you should do is manually create the label type mail merge main
document with the mergefields where you want them and save it as a template
then either your users could use File>New to start a new mailmerge or you
could do that at the appropriate point in your macro. We would need to see
the whole macro and understand the process exactly to determine the best
way.

I doubt that mailmerge is actually the best way to do it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Lorinda

Hi, a little confused, I thought when I hit Reply, it was going to the
newsgroup...??? Not sure about your comment "Please reply to the newsgroup
unless you wish to avail yourself of my services on a paid consulting basis."
Anyway, it is a fairly straightforward macro. I'm sure it is not the best
solution by any stretch, but it's what we've been using for the last 2 or 3
years. It's just opening Word, going out to get a text file, converting it
to a table, adding column headers, then doing the letters/mailing mail merge
portion. I could copy the vba script (that it shows when I debug at the
"..wordbasic...mailmerge propogate..." errormsg) and send if that will help.
I've tried creating the macro on two different machines (both logged in as me
thought) but same result. Any suggestions would be appreciated! Thank you~
 
D

Doug Robbins - Word MVP

The "Please reply to the newsgroup ..." is part of the signature line that I
use in all responses that I post to the newsgroups.

The only way to resolve your problem will be for you to copy and paste all
of the code from the macro into a message that you post back to the
newsgroups so that we can see what the code is actually doing.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Lorinda

Hi Doug, thanks for the comments. I'm attaching the code for that macro.
Hope this helps!

Sub Labels()
'
' Labels Macro
' Macro recorded 1/11/2006 by LSJ8540
'
ChangeFileOpenDirectory "G:\Headers\"
Documents.Open FileName:="""DISCHARGE LABLES""",
ConfirmConversions:=False _
, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, Encoding:=1252
Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByCommas, NumColumns:=9, _
NumRows:=127, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=12, Extend:=wdExtend
Selection.InsertRowsAbove 1
Selection.TypeText Text:="dr#"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="drlname"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="drfname"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="adm"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="dis"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="dob"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="plname"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="pfname"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="visit#"
ActiveDocument.SaveAs FileName:="DISCHARGE LABLES.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Close
Documents.Add DocumentType:=wdNewBlankDocument
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
ActiveDocument.MailMerge.OpenDataSource Name:= _
"G:\Headers\DISCHARGE LABLES.doc", ConfirmConversions:=False,
ReadOnly:= _
False, LinkToSource:=True, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:= _
"", Revert:=False, Format:=wdOpenFormatAuto, Connection:="",
SQLStatement _
:="", SQLStatement1:="", SubType:=wdMergeSubTypeOther
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""dr"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""drlname"""
Selection.TypeText Text:=", "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""drfname"""
Selection.TypeParagraph
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""adm"""
Selection.TypeText Text:=" - "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""dis"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""dob"""
Selection.TypeParagraph
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""plname"""
Selection.TypeText Text:=", "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""pfname"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""visit"""
WordBasic.MailMergePropagateLabel
End Sub

The error appears after the macro has gone through and one label shows the
placeholders for the data. When I click the Debug option at the error, it
shows this code above and the second line from the bottom is hi-lited yellow.

Thanks for you help!
 
D

Doug Robbins - Word MVP

Your problem is that

Documents.Add DocumentType:=wdNewBlankDocument
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

does not by itself create a mailing label type mail merge main document.
There is nothing in the code to either select the type of label or create a
table in the main document that can serve as a labels. Hence, the
propogatelabel command cannot be used.

I would suggest that you create a template that contains the type of label
that you want to use, set up with the mergefields already propogated through
it and then use the command:

Documents.Add "Template Name"

to create a new document from the template

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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