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