View Single Post
  #13   Report Post  
Murray Muspratt-Rouse Murray Muspratt-Rouse is offline
Member
 
Location: Mill Hill, London, England
Posts: 44
Default

I think I have overcome the Tools/References problem, but now I have another one: - I get an compile error message telling me that End of Statement was expected, highlighting FileName in the statement to which I have added 'Set objMMMD ='

Set objMMMD = objApp.Documents.Open FileName:=strDocName, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False _
, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", XMLTransform:=""

Murray

Quote:
Originally Posted by Peter Jamieson View Post
That is probably because the Word Object library has not been referenced via
the Tools|References option in Access VBA. However, the original author may
have avoided that deliberately because when you reference a library, the
reference is to a specific version of Word.

You can typically work around that using the following instead (you just
don't see the autocomplete Help in the VBA editor that you would otherwise
get)

Dim objMMMD As Object

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Murray Muspratt-Rouse" wrote
in message ...[color=blue][i]

Thank you Doug for referring me to Peter Jamieson's advice. I have
immediately run in to a problem - it does not like 'objMMMD As
Word.Document' telling me 'User-defined type not defined' and
suggesting that it might be in a properly registered object or type
library. Did I misunderstand Peter's advice? Was I meant to change
objMMMD to something else?

Murray

Doug Robbins - Word MVP;359552 Wrote:
Actually, I did know what the code was doing, but did not understand
why.

However, I suggest that you follow the advice given by Peter Jamieson
and
use

Dim objMMMD As Word.Document
'
'
'
Set objMMMD = objApp.Documents.Open FileName:=strDocName, 'etc.
'
'
'
' then when you want to close the mail merge main document, instead of
having to
' work out which window it is in, you can do

objMMMD.Close SaveChanges:=False
'
' then

Set objMMMD = Nothing


--
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

"Murray Muspratt-Rouse"

wrote
in message
...

I agree with Doug about the code he does not understand - since I am
not
the original author of this code and do not speak VBA any way I have
been struggling to find my way to add new function to the
application.

The merge document is selected by the user from an Access table in
which the full path to the file is stored, so what the code that we
cannot understand does is to strip off the path to the document from
strDocName: -
Dim intSplitName As Integer
Dim intLength As Integer
intLength = Len(strDocName)
intSplitName = InStrRev(strDocName, "\", , vbTextCompare)
strDocName = Right(strDocName, intLength - intSplitName)


objApp.Windows(strDocName).Activate
objApp.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
So perhaps what the last line does is to shut the new document, since
the original merge document is displayed. I have tried commenting out
this code but that only results in an error. I will try changing
ActiveWindow in the last line to strDocName!

Many thanks for your time and trouble

Murray



+-------------------------------------------------------------------+
+-------------------------------------------------------------------+



--
Murray Muspratt-Rouse