Changing Project Items in Existing documents

R

rsegijn

Changing Project Items in Existing documents

A couple of years ago my colleague created some macro's for mailmerge.
From our C/S application a mergefile was placed in folder C:\Temp.
The name of this mergefile is always [DocumentName].DAT

We deployed a set of template documents which contained a number of
macro's and in one of the modules the corresponding Mergefile is
determined by:

++++ Code snippet +++
<< Module Call_Functions >>
Public Function OpenDatafile$()
Dim Count
Dim Filenaam$, Datafile$

Filenaam$ = WordBasic.[FileName$]()
Count = Len(Filenaam$)
While Mid(Filenaam$, Count, 1) <> "\" And Count > 1
Count = Count - 1
Wend
OpenDatafile$ = "c:\temp\" + Mid(Filenaam$, Count + 1, InStr(Count + 1,
UCase(Filenaam$), ".DOC") - Count) + "DAT"
End Function
++++ Code snippet +++

I want to get rid of this hard reference to the folder C:\Temp and
replace it with:

OpenDatafile$ = Environ("TEMP") + "\" + Mid(Filenaam$, Count + 1,
InStr(Count + 1, UCase(Filenaam$), ".DOC") - Count) + "DAT"


I could of course deploy a new set of template documents with the above
modification, but there are 2 problems:

1) the macro's/modules reside in all the documents. And every customer
has created their own documents based on the template documents we
deployed.
So I'll have to change all these documents also, i.e. not only
deploying a new set of template documents.

Luckily, all these documents are in the same directory as the set of
template documents.
And that brings me to problem 2.

2) I could deploy a special document that uses a macro in which by
using:

Application.OrganizerDelete Source:=CustomerDocument,
Name:="Call_Functions", Object:=wdOrganizerObjectProjectItems

Application.OrganizerCopy Source:=MyTemplate,
Destination:=CustomerDocument, Name:="Call_Functions",
Object:=wdOrganizerObjectProjectItems

By running this macro I could change the old module "Call_Functions"
(with the C:\Temp\ reference) with a new module "Call_Functions" (with
the Environ("TEMP") reference) for all the documents in the specified
directory.

But some of our customers have a customer-specific module
"Call_Functions".
The above method would 'destroy' these customer-specific module.


What I am looking for now is automating (OLE) the follow solution for
each document:
1 export the module to a file "X:\Folder\Call_Functions.bas"
2 modify this file by replacing "c\temp\" with Environ("TEMP") + "\"
3 delete the module "Call_Functions" in the document
4 import the modified "X:\Folder\Call_Functions.bas"

Can this be done?
(I know howto achieve step 2 and step 3, but I can't figure out the
first and the last step).
 
C

Cindy M -WordMVP-

Hi Rsegijn,
What I am looking for now is automating (OLE) the follow solution for
each document:
1 export the module to a file "X:\Folder\Call_Functions.bas"
2 modify this file by replacing "c\temp\" with Environ("TEMP") + "\"
3 delete the module "Call_Functions" in the document
4 import the modified "X:\Folder\Call_Functions.bas"

Can this be done?
(I know howto achieve step 2 and step 3, but I can't figure out the
first and the last step).
What you're looking for is part of the VBA Extensibility library
(VBIDE). You'll want to set a reference to that in order to access the
Help. The method you're asking about is Export, for the VBComponent
object.

Note, however, that theoretically you could use this same object model
to make the modifications "in place", rather than exporting / importing
the modules.

A further comment: if these macros are eventually going to be used in
Word 2002 or later, it's possible that the entire construct may fail.
You may want to do some testing on this before going any further so
that you can take any changes necessary for that into account at the
same time.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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