1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Mail Merge Question

Discussion in 'Software Development' started by balloon_tom, Aug 1, 2006.

Thread Status:
Not open for further replies.
  1. balloon_tom

    balloon_tom Thread Starter

    Joined:
    Jan 4, 2006
    Messages:
    107
    Good morning all,
    I have an Excel workbook which contains names and addresses. It also has a form to select one of several envelope sizes and a button to run the following macro which opens the selected envelope mailmerge doc. Most works great. However, ".Application.ActiveDocument.MailMerge.OpenDataSource Name:=s, _" wants to open up a new instance of the same Excel workbook. I need the mailmerge doc to use the data in the already opened Excel without opening a new instance. Is this possible?
    Tom


    Sub Envelope()
    Dim s As String
    Dim wdApp As Word.Application, wdDoc As Word.Document

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then 'Word isn't already running
    Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    s = ActiveWorkbook.FullName
    Set wdDoc = wdApp.Documents.Open("C:\TOM\ADDRESSES\#10_A&B_ENVEL.DOC")
    Application.AskToUpdateLinks = False
    With wdApp
    .Visible = True
    .Activate
    .WindowState = wdWindowStateMaximize
    .ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitFullPage
    .Application.ActiveDocument.MailMerge.MainDocumentType = wdFormLetters

    PROBLEM LINE:
    .Application.ActiveDocument.MailMerge.OpenDataSource Name:=s, _
    ConfirmConversions:=False, _
    ReadOnly:=False, _
    LinkToSource:=True, _
    Revert:=False, _
    Format:=wdOpenFormatAuto, _
    Connection:="Data Source=" & s & ";Mode=Read", _
    SQLStatement:="SELECT * FROM `addresses$`", _
    SubType:=wdMergeSubTypeAccess


    .Application.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
    .Application.ActiveDocument.MailMerge.DataSource.ActiveRecord = Val(LineNum)
    End With
    End Sub
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Mail Merge Question
  1. leachim
    Replies:
    0
    Views:
    91
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/488366

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice