Page 1 of 1 1
Topic Options
#7709 - 2001-03-24 12:22 AM Loading a macro from one template to another
Anonymous
Unregistered


I've been developing a Kix script that will automate the rollout of new computers and you guy's posts have been invaluable to me. Thanks a million! I've run into a problem that I have no idea how to handle and I figured I'd ask you folks. First off let me say Yes, I've read the Kix manual (several times) and yes I've gone through all the posts. My problem is that we have a macro we use here at work that's contained in a master template on one of our servers and I need an automated way to copy it to a users template when we set up their PC. I cannot simply overwrite the users template with the master as each user has their own settings.
Also a reference library is needed along with the macro. It's the groupware library. I suspect OLE is needed but I've never worked with it and the manual sucks on this subject. From what I've read Shawn is your resident expert on OLE but none of his examples are even close to what I want to do.(Or maybe I missed something) Anyway, can anyone put me on the right track? Perhaps I should be considering something other than Kixtart. Maybe VB Script? I don't know. From what I've seen though, Kixtart can do just about anything. Any help you can provide is much appreciated.

P.S. I'm only working with NT 4.0 right now.

Thanks

Top
#7710 - 2001-03-28 03:27 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
kirm

How you making out with this one ?

I did a little digging into using OLE to do this and was dismayed to find that one cannot use OLE to extract/insert macro's from one template to another... you can load them into a document and you can invoke them, but you can't move them around (?).

Have you found another solution ?

Shawn.

Top
#7711 - 2001-03-28 07:30 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


No, I've found nothing. You guys were pretty well my last hope but I haven't given up yet. I've searched Microsoft's web site for hours. Forget it. Searching their site is like trying to find a needle in a haystack.

I know that in Access you can programatically make a module and add code to it. So maybe I should be looking down that path. But...I'd have to change the module into a macro. Don't know about that one. Anyhow, If you have some other ideas let me know.

Top
#7712 - 2001-03-28 09:08 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I'm trying to brush-up on my winword skills... I'm thinking maybe you could extract the macro from the server template into a text file, then use OLE to automate a push into the user's termplate. Which template needs this macro ? normal.dot or some other template ?

Shawn.

excuse me if i'm using the wrong terminolgies here !

Shawn..

Top
#7713 - 2001-03-29 03:18 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Kirm

With your permission, we can take this one step at a time... let's first try to enumerate all the user's templates (addins?) to see if we can get a handle to them. Try running this script to see if the template(s) in question show up...

code:

break on cls

$word = olecreateobject("word.application")

if $word

$addins = val("&"+olegetproperty($word,"addins"))

if $addins

$enum = oleenumobject($addins)

if $enum

$addin = oleenumobject($addins,$enum)

if $addin

?"Addins:"

while @error = 0

? olegetproperty($addin,"name")

$= olereleaseobject($addin)

$addin = oleenumobject($addins,$enum)

loop

$= olereleaseobject($addin)

endif

$= olereleaseobject($enum)

endif

$= olereleaseobject($addins)

endif

$= olecallfunc($word,"quit")

$= olereleaseobject($word)

endif

exit


Shawn.

[This message has been edited by Shawn (edited 29 March 2001).]

Top
#7714 - 2001-03-29 09:29 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
kirm

you still with us ?

Top
#7715 - 2001-04-02 08:06 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


Yeap I'm here. You'll have to excuse the absense I'm in the middle of a rollout now and we're hopping. In addition, I don't have the Internet at home. I haven't tried what you posted Shawn but I'm going to now. It looks interesting and it may work. I'll get back to you shortly with the results.

kirm

Top
#7716 - 2001-04-02 08:42 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


OK I tried it and here's what happened: First off the code runs great and I can here word opening(disk activity). Single stepping the code I come to this part

while @error = 0
? olegetproperty($addin,"name")
$= olereleaseobject($addin)
$addin = oleenumobject($addins,$enum)
loop

It goes through the loop once and continues on. I wanted to see what was happening so I added this

$r=olegetproperty($addin,"name")
? "addin is " + $r

I think this is what the second line of the loop is supposed to do but I wanted confimation.

Anyhow this is what I get:

addin is

Obviously olegetproperty($addin,"name") isn't returning anything. What does this mean? I assume this isn't a good sign. I am also assuming(I know little about OLE) that you were trying to enumerate the add-ins in word, Shawn. Is that correct? I can tell you that I do have the macro installed and I don't know why it isn't being returned unless addins doesn't include macros. That doesn't make sense though.

Anyhow that was a cool exercise. Thanks Shawn. If you have any other ideas let me know.

Kirm

P.S. How's the weather in TO? Here it sucks. I've had the opportunity to visit your city once about 6 years ago and I was very impressed. It's a beautiful city.

Top
#7717 - 2001-04-02 10:29 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hey - how it's going eh ?

Didn't see that your from Edmonton. Weather is mild here today... how's things out West ?

Anyway, from one hoser to another...

try changing this line...

$addins = val("&"+olegetproperty($word,"addins"))

to this...

$addins = val("&"+olegetproperty($word,"templates"))

Any different ?

Shawn.

[This message has been edited by Shawn (edited 02 April 2001).]

Top
#7718 - 2001-04-03 12:21 AM Re: Loading a macro from one template to another
Anonymous
Unregistered


That did it! It brought back normal.dot. Although it's pretty cool, I still don't understand how that will help me merge the macro. Any Ideas?
Top
#7719 - 2001-04-04 04:40 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok Kirm...

This has become a bit of a vandetta on my part... you've probably got some work-around by now and if you do - cudo's. But now it's just gotten personal. We Canadians can be persistent bastards, can't we ?

This script will do two things...

1) Enumerate all the VB CodeModules (macros) in Normal.dot

2) Add a VB macro module into normal.dot if it doesn't already exist.

One can manually see and verify all the module names and sourcecode using the following winword menu item ...

tools->macro->macros...->organizer

Always use the organizer when managing macro modules (adding,deleting).

Here's the macro module. Change the script variable $module_file to point to the module.

[file: kixtart.bas]

code:

Attribute VB_Name = "KiXtart"
Sub KixRox()
Attribute KIXTART.VB_Description = "Macro recorded 10/08/99 by Shawn"
Attribute KIXTART.VB_ProcData.VB_Invoke_Func = "Normal.KiXtart.KixRox"


'
' KIXTART Macro
' Macro recorded 10/08/99 by Shawn
'

Selection.TypeText Text:="KiXtart 2001 Rox !"


End Sub


and the script...

code:

break on cls


$module_name = "kixtart" ; <--- module name ?
$module_file = "m:\macro\kixtart.bas" ; <--- and the filename ?


$vb_ext_ct_classmodule = "1"


$word = olecreateobject("word.application")


if $word


$template = val("&"+olegetproperty($word,"NormalTemplate"))


if $template


$document = val("&"+olecallfunc($template,"openasdocument"))


if $document


$vbproject = val("&"+olegetproperty($document,"vbproject"))


if $vbproject


$vbcomponents = val("&"+olegetproperty($vbproject,"vbcomponents"))


if $vbcomponents

$index = 1
$component = val("&"+olecallfunc($vbcomponents,"item","i","$index"))


while @error = 0


$name = olegetproperty($component,"name")
$type = olegetproperty($component,"type")


if $name = "$module_name" and $type = "$vb_ext_ct_classmodule"
$classmodule = $component
else
$= olereleaseobject($component)
endif
$index = $index + 1
$component = val("&"+olecallfunc($vbcomponents,"item","i","$index"))
loop


$= olereleaseobject($component)


if $classmodule
?"$module_name module already loaded!"
$= olereleaseobject($classmodule)
else
?"Loading $module_name module ... "
$new= val("&"+olecallfunc($vbcomponents,"import","s","$module_file")) "@serror"
$= olereleaseobject($new)
endif


$= olereleaseobject($vbcomponents)


endif


$= olereleaseobject($vbproject)


endif

$= olereleaseobject($document)


endif

$= olereleaseobject($template)

endif


; ?"pause..." gets $k


$= olecallfunc($word,"quit")


$= olereleaseobject($word)


endif


exit


Shawn.

[This message has been edited by Shawn (edited 04 April 2001).]

Top
#7720 - 2001-04-04 08:33 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


Son of a beach ball, I think you've done it! This actually looks like it will work. I'm going to try this and get back to you as soon as possible. Talk to you soon.

Kirm

Top
#7721 - 2001-04-04 09:14 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


You did it Man! Right on! it works perfectly. So perfectly, in fact, that it copied over the original macro with the one I made. This could be a problem if the user already has macros but I'm going to look into it and don't see a problem fixing that. Thanks Shawn!

Kirm

Top
#7722 - 2001-04-04 10:49 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


I've been single stepping your code and I'm beginning to see how it works. It's great to be finally beginning to understand this OLE stuff. You've made me a believer. Two things though; 1) I don't understand why it overwrites or gets rid of other macros. From following the code I can't see where it would do this. I must admit, though, that I haven't fully tested the deletion factor, as I call it. So I'll continue with my experimentation. 2) Do you know of any good sources of information to learn about the exposed methods of the OLE servers? For instance, you used Item and Import in the olecallfunc function. Are there any that would add a menu item and tie it into a macro? Where would I find the Info? You are a fountain of knowledge but I can't keep bugging you forever.

Also where did you learn about that undocumented "s" typelist?(typelist is what the help file calls it).

You used it here:

olecallfunc($vbcomponents,"import","s","$module_file")

Anyway, I still can't believe it works! There really isn't anything that Kixtart can't do.

Kirm

Top
#7723 - 2001-04-04 10:59 PM Re: Loading a macro from one template to another
Anonymous
Unregistered


Sorry Shawn, I was mistaken. After further testing I found that it doesn't overwrite anything.

Kirm

Top
#7724 - 2001-04-07 05:50 PM Re: Loading a macro from one template to another
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Kirm:

No need for apology, your testing the crap out of it and that's a good thing ! One more test for you though. Make sure that when the script finishes, winword.exe terminates cleanly and is NOT still running in the background. I was extra careful to perform proper object cleanup in this script. Winword should exit cleanly. Have a double check though...

The "s" typelist thingy is just something, someone tried along time ago and got to work. Still hasn't made it's way into the documentation yet, eh (?)

Good sources of information ? I just basically hunt and peck around MSDN ! If your interested in learning more about OLE and Automation, here's a link for you...

Microsoft Word Objects

Been a pleasure.

Shawn.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1955 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.065 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org