?
Solved

opening a Word document for mail merge

Posted on 2001-07-23
4
Medium Priority
?
280 Views
Last Modified: 2012-06-27
This is my code for opening a document in Word. The problems are as follows: the documents open as microsoft Word form letter 1. When I want to close them I get the question if I want to save microsoft word form letter1, when I reply to this question, I get the question a second time but then with the name of the document I opened.The document opens also minimized. The user has to click the Word logo and then, click maximize with the right mouse button.

Private Sub CombineDoc(NameDoc As String)

    Dim objWord As Word.Application
    Set objWord = New Word.Application
   objWord.Documents.Open App.path & "\" & Namedoc, ReadOnly:=True
    objWord.Visible = True
    With objWord.ActiveDocument.MailMerge
    If .State = wdMainAndDataSource Then
            .Execute
    Else

    MsgBox "the document" & NameDoc & " isn't prepared for mail merge", vbInformation
    End If
    End With
End Sub

How can I change this code in order to prevent this from happening?
0
Comment
Question by:ELSJE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 300 total points
ID: 6308595
Just add the following line:

objWord.ActiveDocument.Saved = True

Then Word 'thinks' the document is already saved!
You can do this for both files.

D'Mzzl!
RoverM
0
 

Author Comment

by:ELSJE
ID: 6308747
Hi Rover, this helps in the way that I don't get asked anymore if I want to save, but still two documents are opened. Once the document I want to open and once the word form letter 1

Is it not possible to prevent this?
Is it also not possible that I see the document immediately once I click on the Word logo, in stead of clicking and after this maximizing with the right mouse button?
0
 
LVL 12

Expert Comment

by:roverm
ID: 6308945
To prevent this: I don't think so since Word thinks something has changed to the doc's ...

To maximize the correct window:
Just loop through the Documents collection: if your new doc is found, then use the WindowState property to maximize the window:

Sub MaxMyDoc()
Dim oDoc As Document
Dim sMyDoc As String
   
    sMyDoc = "MyNewDocument"
   
    For Each oDoc In Documents
        If UCase(oDoc.Name) = UCase(sMyDoc) Then 'found it
            oDoc.Activate
            ActiveWindow.WindowState = wdWindowStateMaximize
            Exit For
        End If
    Next oDoc

End Sub

D'Mzzl!
RoverM
0
 

Author Comment

by:ELSJE
ID: 6316155
I added another line
objword.activedocument.closed = true
This way the user sees only the document that he wanted to open

thanks

els
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question