PDA

View Full Version : Solved: Calling code from a non referenced template



Gavint
04-04-2007, 10:39 PM
I'm running code from a template and would like to do the following

call up another template
run some code on that template (finds bookmark in table based on specified criteria)
Return to original document with data (using bookmark range copy/paste)Typically I think would be done by storing the 2nd template in a startup directory and referencing the project. However, in this scenario I need to do this without any project references - can it be done?

I'm having trouble loading and switching to the 2nd template to run the code and then returning back to the original document.

I've tried playing with adding and activating without success. eg

dim Doc2 as Document
Doc2 = Documents.Add("DATA.DOT")
Doc2.Activate


As soon as I try and run any code, it crashes out. I guess I'm not sure how to identify both documents appropriately and switch between them to run code.

Bit of a newbie, so please excuse any poor terminology. Thanks!

fumei
04-05-2007, 03:12 AM
Why is the code in a separate template?

However, in any case, you can programmatically add any template as an add-in, then use its code.
AddIns.Add FileName:="C:\Temp\MyLetter.dot", Install:=Trueloads the template MyLetter.dot as an add-in.

It does not open the file. It simply makes the code available.

You can remove it from the Add-in list afterwards with: AddIns("C:\Temp\MyLetter.dot").Delete

Just change:

FileName:="C:\Temp\MyLetter.dot"

to Filename:="yourPath_filename"

Note that templates added in do NOT have to be in the Startup folder. They can be anywhere.