Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Starting MSWord Merge from MSAccess

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word programming
View previous topic :: View next topic  
Author Message
Kathy Webster
Guest





PostPosted: Thu Nov 29, 2007 6:38 pm    Post subject: Starting MSWord Merge from MSAccess Reply with quote

I am collecting info from an MSAccess record and trying to merge it in Word.
I would like this to work with any version of Word that the user may have
installed. My MSAccess app will be a runtime app that I will be putting on
various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ", False,
False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has disconnected
from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc", FileFormat:=0

Thanks in advance,
Kathy
Back to top
Google
Sponsor





PostPosted: Thu Nov 29, 2007 6:38 pm    Post subject: Advertisement

Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Thu Nov 29, 2007 7:22 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
Quote:
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user may
have installed. My MSAccess app will be a runtime app that I will be
putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ", False,
False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has disconnected
from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy
Back to top
Kathy Webster
Guest





PostPosted: Thu Nov 29, 2007 8:37 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

I think I wasn't clear. It is successful up to and including :

Quote:
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

It bombs when executing this next line:

wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

....with the message "The object invoked has disconnected from its clients."
I don't know how to reactivate the screen that shows the RESULTS of the
merge to new document, and save THAT as "merged_ad.doc"



"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
Quote:
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.
Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Fri Nov 30, 2007 6:20 am    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
Quote:
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user may
have installed. My MSAccess app will be a runtime app that I will be
putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word
and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy


Back to top
Kathy Webster
Guest





PostPosted: Fri Nov 30, 2007 5:11 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

Cool, thanks. I had make 1 change to this line:

wdActiveDoc.Close wdDoNotSaveChanges

to

wdActiveDoc.Close , 0

because it didn't understand wdDoNotSaveChanges

One last thing: Now my Word screen is left with "merged_ad.doc" in the
title bar, and the screen is inactive (gray background, no white "sheet of
paper" ready to go). How can I leave Word with no document in the title bar
and a white "Sheet of paper" on the screen?




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:O2ZbikxMIHA.5988@TK2MSFTNGP02.phx.gbl...
Quote:
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user
may have installed. My MSAccess app will be a runtime app that I will be
putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word
and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy




Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Fri Nov 30, 2007 7:17 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

Earlier in your code, you have turned off ScreenUpdating

Try adding the following at the end.

wd.ScreenUpdating = True
wd.ScreenRefresh
wd.ActiveDocument.Close
wd.Documents.Add

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47504432$0$8823$4c368faf@roadrunner.com...
Quote:
Cool, thanks. I had make 1 change to this line:

wdActiveDoc.Close wdDoNotSaveChanges

to

wdActiveDoc.Close , 0

because it didn't understand wdDoNotSaveChanges

One last thing: Now my Word screen is left with "merged_ad.doc" in the
title bar, and the screen is inactive (gray background, no white "sheet of
paper" ready to go). How can I leave Word with no document in the title
bar and a white "Sheet of paper" on the screen?




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:O2ZbikxMIHA.5988@TK2MSFTNGP02.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user
may have installed. My MSAccess app will be a runtime app that I will
be putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word
and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy






Back to top
Kathy Webster
Guest





PostPosted: Fri Nov 30, 2007 10:52 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

You da bomb...Thanks!
One last question...I hope...
How do I modify this line you gave me, so that "merged_ad.doc" doesn't show
up on the recently edited docs list?

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:OMl6yW4MIHA.5160@TK2MSFTNGP05.phx.gbl...
Quote:
Earlier in your code, you have turned off ScreenUpdating

Try adding the following at the end.

wd.ScreenUpdating = True
wd.ScreenRefresh
wd.ActiveDocument.Close
wd.Documents.Add

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47504432$0$8823$4c368faf@roadrunner.com...
Cool, thanks. I had make 1 change to this line:

wdActiveDoc.Close wdDoNotSaveChanges

to

wdActiveDoc.Close , 0

because it didn't understand wdDoNotSaveChanges

One last thing: Now my Word screen is left with "merged_ad.doc" in the
title bar, and the screen is inactive (gray background, no white "sheet
of paper" ready to go). How can I leave Word with no document in the
title bar and a white "Sheet of paper" on the screen?




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:O2ZbikxMIHA.5988@TK2MSFTNGP02.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user
may have installed. My MSAccess app will be a runtime app that I will
be putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that
you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word
and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use
late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy








Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Sat Dec 01, 2007 1:42 am    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

Use

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc", SaveToRecentFiles:
= False

or, as you seem to have had troubled with using named parameters, you may
need to use

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc","","","", False



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47509462$0$16483$4c368faf@roadrunner.com...
Quote:
You da bomb...Thanks!
One last question...I hope...
How do I modify this line you gave me, so that "merged_ad.doc" doesn't
show up on the recently edited docs list?

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:OMl6yW4MIHA.5160@TK2MSFTNGP05.phx.gbl...
Earlier in your code, you have turned off ScreenUpdating

Try adding the following at the end.

wd.ScreenUpdating = True
wd.ScreenRefresh
wd.ActiveDocument.Close
wd.Documents.Add

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47504432$0$8823$4c368faf@roadrunner.com...
Cool, thanks. I had make 1 change to this line:

wdActiveDoc.Close wdDoNotSaveChanges

to

wdActiveDoc.Close , 0

because it didn't understand wdDoNotSaveChanges

One last thing: Now my Word screen is left with "merged_ad.doc" in the
title bar, and the screen is inactive (gray background, no white "sheet
of paper" ready to go). How can I leave Word with no document in the
title bar and a white "Sheet of paper" on the screen?




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:O2ZbikxMIHA.5988@TK2MSFTNGP02.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a document
object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it in
Word. I would like this to work with any version of Word that the user
may have installed. My MSAccess app will be a runtime app that I will
be putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that
you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both
Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use
late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy










Back to top
Kathy Webster
Guest





PostPosted: Mon Dec 03, 2007 5:48 pm    Post subject: Re: Starting MSWord Merge from MSAccess Reply with quote

Unfortunately, it didn't like either of those, but I messed with it, and it
likes:
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc", _
0, False, "", False, "", False, False, False, False, False

Thank you!


"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:%2353kvt7MIHA.4480@TK2MSFTNGP06.phx.gbl...
Quote:
Use

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc",
SaveToRecentFiles: = False

or, as you seem to have had troubled with using named parameters, you may
need to use

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc","","","", False



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47509462$0$16483$4c368faf@roadrunner.com...
You da bomb...Thanks!
One last question...I hope...
How do I modify this line you gave me, so that "merged_ad.doc" doesn't
show up on the recently edited docs list?

wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:OMl6yW4MIHA.5160@TK2MSFTNGP05.phx.gbl...
Earlier in your code, you have turned off ScreenUpdating

Try adding the following at the end.

wd.ScreenUpdating = True
wd.ScreenRefresh
wd.ActiveDocument.Close
wd.Documents.Add

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47504432$0$8823$4c368faf@roadrunner.com...
Cool, thanks. I had make 1 change to this line:

wdActiveDoc.Close wdDoNotSaveChanges

to

wdActiveDoc.Close , 0

because it didn't understand wdDoNotSaveChanges

One last thing: Now my Word screen is left with "merged_ad.doc" in the
title bar, and the screen is inactive (gray background, no white "sheet
of paper" ready to go). How can I leave Word with no document in the
title bar and a white "Sheet of paper" on the screen?




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:O2ZbikxMIHA.5988@TK2MSFTNGP02.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc"

use

wdActiveDoc.Close wdDoNotSaveChanges
wd.ActiveDocument.SaveAs "K:\legalper\merged_ad.doc"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:eGhrj0rMIHA.484@TK2MSFTNGP06.phx.gbl...
In place of

wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0

use

wdActiveDoc.Close wdDoNotSaveChanges

Note, you do not show that you have declared wdActiveDoc as a
document object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:474f0729$0$2338$4c368faf@roadrunner.com...
I am collecting info from an MSAccess record and trying to merge it
in Word. I would like this to work with any version of Word that the
user may have installed. My MSAccess app will be a runtime app that
I will be putting on various machines in different workplaces.
Here is the code I am running from MSAccess:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that
you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both
Word and
'Access. As well, I changed the type,
since
'(like Word.Application), you have to use
late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
'It bombs here with "Automation error: The object invoked has
disconnected from its clients", and the next line is highlighted.
'What I'm trying to do here is open merge_ad.doc, merge it, close
merge_ad.doc, then save the
'resulting merged doc as "merged_ad.doc"
wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
FileFormat:=0

Thanks in advance,
Kathy












Back to top
Kathy Webster
Guest





PostPosted: Mon Dec 03, 2007 7:53 pm    Post subject: Adding to recent files list Reply with quote

On a related note,
Now that I'm starting to work with this other similar part of the code
(except this is opening the doc, rather than saving as...), I have found
that even though I think I have specified to leave merge_ad.doc off of the
Recently edited files list, it's still showing up:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ", False,
False, False, "", "", False, "", "", 0)

Can anyone figure out why?
Back to top
Kathy Webster
Guest





PostPosted: Wed Dec 05, 2007 1:19 am    Post subject: Re: Adding to recent files list Reply with quote

Anyone??

"Kathy Webster" <slickdock@yahoo.com> wrote in message
news:47545ecb$0$9868$4c368faf@roadrunner.com...
Quote:
On a related note,
Now that I'm starting to work with this other similar part of the code
(except this is opening the doc, rather than saving as...), I have found
that even though I think I have specified to leave merge_ad.doc off of the
Recently edited files list, it's still showing up:

Public Function AddressBlock() As Boolean

Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use late
'binding.

Set wd = CreateObject("Word.Application")
wd.Visible = True

wd.Application.ScreenUpdating = False

Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ", False,
False, False, "", "", False, "", "", 0)

Can anyone figure out why?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum