J
Jeff
Hi,
I have a program that replaces the code of templates with new up to date
templates. It deletes all the old code modules and inserts the new ones.
It does this fine. However some of the old templates have code behind
the thisDocument part of the template that needs deleting for the new
templates to work. I can do this manually but is there a way to do it
via vba? I have well over 2000 documents to convert!!! I'm using Delphi
and the COM but I can convert the vba solution into Delphi. (the object
model is the same).
Code so far (Delphi but you should reconise the objects)
{ Removes Old VBA Code }
NoOfVBComps := OldDoc.VBProject.VBComponents.Count;
finished := false;
VBCompPos := 1;
count := 0;
while (not finished) do
begin
oleVar := VBCompPos;
try
oleVar2 := OldDoc.VBProject.VBComponents.Item(oleVar).Name;
OldDoc.VBProject.VBComponents.Remove
(OldDoc.VBProject.VBComponents.Item(oleVar2));
except
inc(VBCompPos);
end;
inc(count);
if count = NoOfVBComps then
finished := True;
end;
{ Add new code }
OldDoc.VBProject.VBComponents.Import(ExtractFilePath(ParamStr(0)) +
'NewCode1.bas');
OldDoc.VBProject.VBComponents.Import(ExtractFilePath(ParamStr(0)) +
'NewCode2.bas');
This deletes all the modules and replaces them but leaves the code behind
thisDocument untouched. Any help would be most welcome.
Thanks
Jeff
I have a program that replaces the code of templates with new up to date
templates. It deletes all the old code modules and inserts the new ones.
It does this fine. However some of the old templates have code behind
the thisDocument part of the template that needs deleting for the new
templates to work. I can do this manually but is there a way to do it
via vba? I have well over 2000 documents to convert!!! I'm using Delphi
and the COM but I can convert the vba solution into Delphi. (the object
model is the same).
Code so far (Delphi but you should reconise the objects)
{ Removes Old VBA Code }
NoOfVBComps := OldDoc.VBProject.VBComponents.Count;
finished := false;
VBCompPos := 1;
count := 0;
while (not finished) do
begin
oleVar := VBCompPos;
try
oleVar2 := OldDoc.VBProject.VBComponents.Item(oleVar).Name;
OldDoc.VBProject.VBComponents.Remove
(OldDoc.VBProject.VBComponents.Item(oleVar2));
except
inc(VBCompPos);
end;
inc(count);
if count = NoOfVBComps then
finished := True;
end;
{ Add new code }
OldDoc.VBProject.VBComponents.Import(ExtractFilePath(ParamStr(0)) +
'NewCode1.bas');
OldDoc.VBProject.VBComponents.Import(ExtractFilePath(ParamStr(0)) +
'NewCode2.bas');
This deletes all the modules and replaces them but leaves the code behind
thisDocument untouched. Any help would be most welcome.
Thanks
Jeff