• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5491
  • Last Modified:

MailMerge .Destination = wdSendToNewDocument not working in Office 2007.

The below VB codes are not working with Office 2007, these work for Office 2000. Do I need to add a Reference.

It errors out on the .Destination line.

With oDoc.MailMerge     'merge data into form letter
        .Destination = wdSendToNewDocument
        .MailAsAttachment = False
        .MailAddressFieldName = ""
        .MailSubject = ""
        .SuppressBlankLines = True
        With .DataSource
            '.FirstRecord = 1
            '.LastRecord = 1
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=True
        '.Activate
    End With
0
DCrats
Asked:
DCrats
  • 4
  • 3
  • 3
  • +2
1 Solution
 
EDDYKTCommented:
yes or just put

With oDoc.MailMerge     'merge data into form letter
        .Destination = 0
        .MailAsAttachment = False
        .MailAddressFieldName = ""
        .MailSubject = ""
        .SuppressBlankLines = True
        With .DataSource
            '.FirstRecord = 1
            '.LastRecord = 1
            .FirstRecord = 1
            .LastRecord = -16
        End With
        .Execute Pause:=True
        '.Activate
    End With
0
 
geneusCommented:
I think there is an issue with this version of VBA as I errored out as well . . . and I recorded the Merge.  However it works if you use the full line outside of the With statement:

ActiveDocument.MailMerge.Destination = wdSendToNewDocument
0
 
GrahamSkanCommented:
What is the error message?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
geneusCommented:
I tried EDDYKT's suggestion successfully.  It appears that the enumeration wdSendToNewDocument is failing.
0
 
geneusCommented:
The error message that I received was:

Run-time error '5852':
Requested object is not available
0
 
EDDYKTCommented:
are you working on vb or vba?
0
 
geneusCommented:
Sorry.  Missed the categories.
I was working in Word 2007 - VBA.
0
 
EDDYKTCommented:
then where do you set oDoc?
May be go for geneus's suggestion

ActiveDocument.MailMerge.Destination = wdSendToNewDocument
0
 
DCratsAuthor Commented:
I tried

    ActiveDocument.MailMerge.Destination = wdSendToNewDocument
    ActiveDocument.MailMerge.MailAsAttachment = False
    ActiveDocument.MailMerge.MailAddressFieldName = ""
    ActiveDocument.MailMerge.MailSubject = ""
    ActiveDocument.MailMerge.SuppressBlankLines = True
    ActiveDocument.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord
    ActiveDocument.MailMerge.DataSource.LastRecord = wdDefaultLastRecord
    ActiveDocument.MailMerge.Execute Pause:=True

Get error "Object variable or With block variable not set".
0
 
DCratsAuthor Commented:


oDoc is set like this

    Set oDoc = moWord.Documents.Open(sFileDot)

    New codes without "With"

    oDoc.MailMerge.Destination = wdSendToNewDocument
    oDoc.MailMerge.MailAsAttachment = False
    oDoc.MailMerge.MailAddressFieldName = ""
    oDoc.MailMerge.MailSubject = ""
    oDoc.MailMerge.SuppressBlankLines = True
    oDoc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord
    oDoc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord
    oDoc.MailMerge.Execute Pause:=True

When I put my cursor at  oDoc.MailMerge.Destination it has value -1 and wdSendToNewDocument has value 0. It did not give error message.
0
 
DCratsAuthor Commented:
The problem is resolved... This is what I had to do:

The document is linked to a data source....and I got this message when I open the document in word. You receive the "Opening this will run the following SQL command" message when you open a Word mail merge main document that is linked to a data source


Word 2007
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options

"SQLSecurityCheck"=dword:00000000
1. Start Registry Editor.
2. Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
3. On the Edit menu, point to New, and then click DWORD Value.
4. Under Name, type:
SQLSecurityCheck
5. Double-click SQLSecurityCheck.
6. In the Value data box, type:
00000000  
7. Click OK.
0
 
Computer101Commented:
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now