Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

runtime error 509:

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lorinda - 24 Dec 2005 17:44 GMT
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
Wibs - 24 Dec 2005 18:08 GMT
Error 509 can occur when attempting to run a macro on a protected
document. Check the document's security settings.

Regards

Wibs
Lorinda - 24 Dec 2005 18:26 GMT
Thanks, I"ll check it out.  

> Error 509 can occur when attempting to run a macro on a protected
> document. Check the document's security settings.
>
> Regards
>
> Wibs
Lorinda - 24 Dec 2005 18:28 GMT
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!

> Error 509 can occur when attempting to run a macro on a protected
> document. Check the document's security settings.
>
> Regards
>
> Wibs
Doug Robbins - Word MVP - 24 Dec 2005 21:13 GMT
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.

Signature

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

> Hi, this document isn't protected.  I can run the macro fine up to the
> point
[quoted text clipped - 9 lines]
>>
>> Wibs
Lorinda - 24 Dec 2005 22:23 GMT
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~

> When I run that code, I get the following after the 509
>
[quoted text clipped - 20 lines]
> >>
> >> Wibs
Doug Robbins - Word MVP - 25 Dec 2005 07:13 GMT
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.

Signature

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

> Hi Doug, thanks.  Well, I'm not actually using vba to create it.  Here's
> the
[quoted text clipped - 46 lines]
>> >>
>> >> Wibs
Lorinda - 26 Dec 2005 19:00 GMT
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~

> 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
[quoted text clipped - 55 lines]
> >> >>
> >> >> Wibs
Doug Robbins - Word MVP - 30 Dec 2005 12:12 GMT
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.

Signature

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

> 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
[quoted text clipped - 85 lines]
>> >> >>
>> >> >> Wibs
Lorinda - 11 Jan 2006 15:00 GMT
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!

> The "Please reply to the newsgroup ..." is part of the signature line that I
> use in all responses that I post to the newsgroups.
[quoted text clipped - 92 lines]
> >> >> >>
> >> >> >> Wibs
Doug Robbins - Word MVP - 11 Jan 2006 19:27 GMT
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

Signature

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

> Hi Doug, thanks for the comments.  I'm attaching the code for that macro.
> Hope this helps!
[quoted text clipped - 221 lines]
>> >> >> >>
>> >> >> >> Wibs
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.