Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Meged Doc in Word 2000 produces file without data

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

I have an app that merges data from an Excel spreadsheet into a form letter in Word. This works great as long as there is more than one record. With one record, I get two docs, and with no data I get one doc.

If I do it manually, it works fine.

Here's my code:

Code:
Public Sub MergeDoc(ByVal DocName As String, ByVal SaveName As String)
        
        If WD.Visible = False Then WD.Visible = True
        OpenDocument (DocName)
        
        With WD
            
            With .ActiveDocument.MailMerge
                .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
                .Execute
            End With
        
          On Error GoTo NoFile
        End With
        SaveAs (SaveName)

        Select Case SaveName
            Case DefPath & "Letters\JuvExpired" & sM & sD & sY & ".doc"
                Expired = CountPages()
                InsertData "EXPIRED", "LETTER", Expired, "JuvExpired" & sM & sD & sY & ".doc"

            Case DefPath & "Letters\JuvDecline" & sM & sD & sY & ".doc"
                Denied = CountPages()
                InsertData "DECLINED", "LETTER", Denied, "JuvDecline" & sM & sD & sY & ".doc"

            Case DefPath & "Letters\JuvInvalid" & sM & sD & sY & ".doc"
                Invalid = CountPages()
                InsertData "INVALID", "LETTER", Invalid, "JuvInvalid" & sM & sD & sY & ".doc"

        End Select
        WD.DisplayAlerts = wdAlertsNone
        WD.ActiveDocument.Close (False)
        Exit Sub
NoFile:
            
            WD.ActiveDocument.Close (False)
       
End Sub
=============================

    Public Sub OpenDocument(ByVal FileName As String)

            WD.Documents.Open FileName, ConfirmConversions:=False, _
                    ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
                    PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
                    WritePasswordTemplate:="", Format:=Word.WdOpenFormat.wdOpenFormatAuto
        
End Sub

Any help will be greatly appreciated.

Thanks,



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top