Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Template with in a macro

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I'm having a problem with switching windows in a macro, the file causing the problem is a template file. Assume the template is called template.xlt, have tried the code

    windows("Template.xlt").activate

    this gives me the error message "Subscript out of range"

    I notice that once my template has been updated, Excel renames it as "Template1", and if I run the macro again "Template2". I have tried various ways of activating these files without any joy.

    Is there anyway of activating my file?

    Thanks

    Matt

  2. #2
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Matt,

    I believe that the problem is that you are activating a window that displays the workbook (template) rather than the workbook itself. Since window names are assigned dynamically as you create them, it is sometimes hard to know what the name is. For example, if you have a template named Template1.xlt, then the window name might be "Template1", but if you have more than one window open into Template1, then the two windows will be called "Template1:1" and "Template1:2". If you don't get the name exactly right, you will get the error message you mentioned. I suggest you use

    Workbooks("Template1.xlt").Activate

    rather than the Window object.
    Keep Excelling.

    Damon

    VBAexpert Excel Consulting
    LinkedIn Profile http://www.linkedin.com/pub/damon-ostrander/7/79/a93
    AllExperts Profile http://www.allexperts.com/ep/1059-30...-Ostrander.htm

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Damon, I think that is the only solution.

  4. #4
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Matt

    If your Workbook is still a template, try

    windows("Template").activate

    Providing it's called "Template" of course!


    _________________
    Kind Regards
    Dave Hawley
    OzGrid Business Applications
    Microsoft Excel/VBA Training
    If it's Excel, then it's us!

    [ This Message was edited by: Dave Hawley on 2002-03-12 01:08 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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