Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Attach template then run it (WinNT/Word97)

    I am trying to put a plain sub in normal.dot, that will attach a template to the activedocument and then run a sub in that template. The normal sub needs to be plain because it needs to run the of that name (at trocnew.dot) no matter what actual address T: is at. If you see what I mean ...! <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15>

    Anyway, attaching the template was the easy bit - activedocument.attachedtemplate = "trocnew.dot" - but I just can't work out the line to get a sub within it to run! No matter what I try, since the template isn't attached to the normal.dot, the debug compiler just says no such thing. At least I think that's why it's saying it!

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> what am I doing wrong, please?! <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>

    Many thanks!

    PS Hitting 'bronzelounger' doesn't seem to have made me any smarter!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attach template then run it (WinNT/Word97)

    Try

    Application.Run "SubName"

    where SubName must be replaced with the name of the procedure. If it has arguments, add them as follows:

    Application.Run "SubName", Argument1, Argument2

    See Run in the VBA help for more info.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Hi Hans, thanks for that and yes, it does seem to be what I want, but for all that it doesn't work! <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    My template is called ProcNew.dot, the module is called NewProcedure and the macro RunMe (original, huh?!). My line of code is therefore:

    Application.Run "'ProcNew.dot'!NewProcedure.RunMe"

    I also tried putting the entire path in (it is the template directory in file locations anyway):

    Application.Run "'T:_1stPersonWorkingITProcNew.dot'!NewProcedure.R unMe"

    but I just get "runtime error '4120' bad parameter".

    What am I doing wrong?! <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Aaargh!! I tried a new format, which seemed to be indicated as a method in the help file:

    Application.Run "ProcNew.NewProcedure.RunMe"

    and now I get "runtime error '4633' - cannot run specified macro"!! It doesn't say WHY, or whether it's because it can't see it, or it can see it but still can't run it, or what!!

    Is there somewhere I can find out more information about these flamin' runtime error numbers?!
    Beryl M


  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Just a stab in the dark here... but since you're running to the clock, might be worth a shot.

    Perhaps the .show method won't work if the form has not been initiated/ activated. Perhaps try one of .activate or .initialize methods.

    Alan

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Hi Alan, and thanks for the suggestion, but the form is initialised *after* it's showing (the code to do so is in the form itself) and I just tried the activate method but it still tells me that 'frmProperties' is a variable that isn't. As it were.

    I wouldn't mind it not being able to see the form so much if it hadn't been running code in two different modules in this template by now and therefore having no excuse whatsoever for not being able to see a form in the same template!

    <img src=/S/weep.gif border=0 alt=weep width=21 height=16> It's not fair! <img src=/S/weep.gif border=0 alt=weep width=21 height=16>
    Beryl M


  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    I'm really going to cry now!! <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>

    Okay, I finally got it to work - I discovered that it will only run a macro from thisdocument on an attached template, so I put one in thisdocument saying to run the one in the new module and pointed to that. Great - it worked!

    But now the code in the template that worked perfectly before has stopped working!! A form (stored in the template) is called by code within the template - "frmProperties.show" - now says "method or data member not found" - but I can see the form sitting there!

    <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>Please, please tell me what's going on - I'm supposed to be finishing this by 4pm today and if I can just get this to work I'll make it, but ...!!!

    Many thanks!
    Beryl M


  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attach template then run it (WinNT/Word97)

    What was the deadline? I can't stay up that late...

    Try these and see what you get. Note: all require the template to be loaded. To access code from a template that is not loaded, I believe you need to set a reference to it in your project so that VB can load it on demand.

    <UL><LI>RunMe

    <LI>Call RunMe

    <LI>Application.Run "NewProcedure.RunMe"

    <LI>Application.Run "ProcNew.dot!RunMe"

    <LI>Application.Run "ProcNew.dot!NewProcedure.RunMe"
    (I removed the ' marks, which are needed only if there is a space in the file name)[/list]In theory, at least one of these should work. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    For further discussions in excruciating detail, see <post#=234629>post 234629</post#> and the threads to which it links.

  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Hi, Jefferson, thanks for that, but the only variation I could get to work (as per my earlier post) was to put the code to run it in a sub in the Thisdocument area of the template (which is attached, and therefore accessible) then run that sub from the normal.dot (with just application.run "[subname]").

    The strange thing is, while this works, the line "frmProperties.show", which is requesting a form in that same template, now says variable not found (or whatever)!! 'Application.Run' won't get it moving - is there an equivalent for running forms instead of macros?!

    (By the way, I missed the dealine, but they found some other things they wanted done too and produced at 3:50pm, so I got away with it!)

    Your help is much appreciated! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attach template then run it (WinNT/Word97)

    I'm not sure if you're even supposed to be able to access forms from different projects, or whether they are private by design. I always use a procedure in a regular code module to call a form... but then you're back to the original problem. I wonder whether you should export/delete/import all your modules? Sometimes templates just get bugs that only a rebuild can cure.

  11. #11
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Attach template then run it (WinNT/Word97)

    Well, I tried the export/import bit, Jefferson (do you shorten it to Jeff or always use it in full?!) but it didn't make any difference. However, I since I found a way to make it work - I moved the whole kit and caboodle from its own module to the ThisDocument one - then the form ran.

    I'm sure it must be possible to run a form from within a separate module, but I've been trying for several days to make it do so and I haven't been able to (even with the lounge's help!) so I'm going to give up and just leave it in thisdocument!

    Many thanks anyway
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •