Results 1 to 2 of 2

Mail Merge from Excel Issue

Threaded View

  1. #1
    Registered User
    Join Date
    11-21-2013
    Location
    Wirral, England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Mail Merge from Excel Issue

    Hi,

    I have a problem with VBA mail merging. I have a word document which is set up to mail merge, and the data for that mail merge is in the current workbook "Book1.xls". The code below works file and leaves no error messages. The problem i have is that each time the workbook is opened, and the macro is run it leaves a new VBA Project in the project explorer. I think that something isn't closing, because when i close excel and check the task manager, the excel application is closed but the Excel.exe process is still running. The only way around this i've found to be either 1) opening the task manager and ending the process; 2) don't open the file Book1.xls from windows explorer, but open excel and then file open method; 3) restarting the machine altogether.

    Hope someone out there can help! Any help will be greatly appreciated.

    Private Sub CommandButton01_Click()
    
    Dim wd As Object
    Dim wdocSource As Object
    Dim strWorkbookName As String
    
    On Error Resume Next
    Set wd = GetObject(, "Word.Application")
    If wd Is Nothing Then
        Set wd = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    
    Set wdocSource = wd.Documents.Open(Filename:=ThisWorkbook.Path & "\Mailmergedocument.doc")
    
    strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    
    wdocSource.MailMerge.MainDocumentType = wdFormLetters
    
    wdocSource.MailMerge.OpenDataSource _
            Name:=strWorkbookName, _
            AddToRecentFiles:=False, _
            Revert:=False, _
            Format:=wdOpenFormatAuto, _
            Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _
            SQLStatement:="SELECT * FROM `Merge Info$`"
    
    With wdocSource.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
    
    With wdocSource
    
    .MailMerge.MainDocumentType = wdNotAMergeDocument
    
    End With
    
    wd.Visible = True
    wdocSource.Close SaveChanges:=False
    
    Set wdocSource = Nothing
    Set wd = Nothing
    
    End Sub
    Last edited by alansidman; 12-20-2013 at 10:29 AM. Reason: code tags added

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 07-12-2012, 08:11 PM
  2. Replies: 2
    Last Post: 04-19-2012, 02:16 PM
  3. Excel Mail Merge - Rounding issue
    By Devillocks in forum Word Formatting & General
    Replies: 3
    Last Post: 08-21-2010, 12:02 PM
  4. Mail Merge Issue!
    By carlosbourn in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-30-2007, 12:37 PM
  5. Mail Merge issue
    By b_walls1 in forum Excel General
    Replies: 4
    Last Post: 04-02-2006, 03:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1