Very Public Functions

T

Todd K.

I am utilizing some MailMerge code from Anne Troy to open a Word Merge
document from Access, make a copy of the merged document, and close the
original without saving. The code works perfectly on my computer, but this
is to be used by the whole department (both Word Document and Data Source
reside on our server). When I tried it from another computer (let's call it
Computer B), the first thing it did was nothing. Once I reduced the security
in computer B's Word to low, it read the document's "On Open" code, but could
not find the public "DoMailMerge" function. I copied the "public" function
to computer B's NORMAL, and now it works great except it keeps asking me to
verify the data source.

1. Is there a better way to get everyone access to the function besides
recopying it into everyone's NORMAL?
2. Why do I have to keep verifying the data source on Computer B and not on
mine?
 
D

Doug Robbins - Word MVP

How about making the functions really public and copy the code into your
message so that we can see what it is trying to do.

Also, however, if it is an Access application, maybe you should post the
question to an Access Newsgroup.
--
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
 
G

Graham Mayor

You should not be setting other people's macro security to low. They could
unwittingly run malicious macro code.
The better plan would be to put the code in a shared global template and set
the macro security to trust installed templates and add-ins and back to
medium. Macros in documents are always going to cause security issues which
is why they are better in templates.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Todd K.

Shared global template? You just lost me. I did consider putting all of the
code (including the function and OpenDataSource) in the document, but it is
struggling with the line With ActiveDocument.MailMerge. Here is the total
code:

Dim DocName$
DocName = ActiveDocument.Name
With ActiveDocument.MailMerge
..Destination = wdSendToNewDocument
..Execute
End With
Windows (DocName).close wdDoNotSaveChanges
 
T

Todd K.

Sorry, since I received two replies I responded (with the code) to the latest
one. The Access code isn't the problem, all it does is open up the Word
document. That part works great. I would like to code the Word merge
document so that if anyone double-clicked on it, it woudl pull from a
specific data source, make a copy of itself, and close itself without
changes. See code in other response.
 
G

Graham Mayor

The simplest way to deal with this is to save that code in the document with
the macroname AutoNew
Save that document as a template.
Use a shared workgroup template location
http://www.gmayor.com/Template_Locations.htm
Create a new document from the template, the code runs, closes that new
document and leaves the merged doc on screen.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Todd K.

I just figured out that putting this code in the Word Merge document works.
I think this will work on medium security, it's just going to ask everytime
if you want to open it.

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Coal Severance\LGP0204x.mdb", _
LinkToSource:=True, _
Connection:="TABLE TblRptCompletion", _
SQLStatement:="SELECT * FROM [TblRptCompletion]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top