Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: macro change cell color - opens original template (unintended)

  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location

    macro change cell color - opens original template (unintended)

    I created a template for a workschedule. In that template I made a macro, that changes the background color of selected cells. (user selected cells).
    The user is supposed to save the template as a regular excel workbook with activated macros.
    So far so good. When using the "colorchange macro", the cells change color correct, BUT at the same time my original template opens as well.
    The template has other macros in it as well.
    So, how do i prevent the template to open, as I only want the active workbook to be affected by my macro?

    Here's the code Ive used:

    Sub fillcolorblue()
        Selection.Interior.Color = RGB(204, 204, 255)
    End Sub
    Last edited by Aussiebear; 06-15-2025 at 01:40 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    Something in the template (macro, named range, validation, ...) probably has the template name / path hard coded

    Post the template if you can
    Last edited by Aussiebear; 06-15-2025 at 01:40 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,800
    Location
    How are you running the macro? That is probably the source of the problem - i.e. it's linked to the macro in the template.
    Be as you wish to seem

  4. #4
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    Kopi af Kopi af MASTER TIDSREGISTRERING m makroer1.xlsm
    user enters wanted year in sheet "indtastÅr". This determines the name of day in each month, according to formula in hidden sheet "Ark1", row 20 etc.

    When working with the sheets, they can select specific cells and change background color by using the macros yellow, green, red or blue.

    When you activate the "color" macros, the original masterworkbook opens. ???

    So my question is, why does that happen and how can I change that (dont want that to open.)

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    When I run the color macros, it does not seem to ask to open the template. Since I don't have the template, I expected a message

    There are a lot of REF# errors so that might be a place to look further


    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    The macro is not supposed to open the template, as it's open already.
    And I don't get those ref errors on any of my computers.

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,454
    Location
    Quote Originally Posted by chapel View Post
    The macro is not supposed to open the template, as it's open already.
    Why is the template open? Close it and only use the actual workbook based on the template

    And I don't get those ref errors on any of my computers.
    We all do as we don't have the information or cells that Ref error refers to.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    Sorry, what I meant was, the macro is not supposed to open the template. But only work on selected cells in the open workbook (which is the one I posted here).
    The ref-errors you get, is probably the result of the macro trying to open the original template, (which it does on my pc)
    But the problem is, its not supposed to open anything. Its simply supposed to set the background color on selected cells in my active workbook.
    So I dont understand why its trying to open the template with the macro code I posted earlier.

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,454
    Location
    Sorry Chapel but right now you are talking in riddles. The template is something from which you develop a new workbook. The new workbook is something that you might use macros to adjust its limitations to suit the criteria for which it is suitable. Never run macros on your template. So I would advise you to Open your template, save it as a new workbook. Close the template, then run the macros on the newly created workbook to make it suitable for the conditions that you need to be applied.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,290
    Location
    I would think that the issue would be related to what Aflatoon was getting at in post 3, if the file that is opening the template has a macro that is mapped to the original template. This means that when the macro is run in the file that has been 'saved as' it has to open the template file in order to run the macro, as this is where the macro is located.

    So in the below macro window in your template:
    Screenshot 2025-06-17 104514.jpg


    Your macro:
    'Kopi af Kopi af MASTER TIDSREGISTRERING m makroer1.xlsm'!blå.fillcolorblue

    Should read:
    fillcolorblue


    See if it reads with the file name before the macro in your template file?

    If it does, try amending them as above, save the file. Then try the save as again.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    Quote Originally Posted by chapel View Post
    Sorry, what I meant was, the macro is not supposed to open the template. But only work on selected cells in the open workbook (which is the one I posted here).
    The ref-errors you get, is probably the result of the macro trying to open the original template, (which it does on my pc)
    But the problem is, its not supposed to open anything. Its simply supposed to set the background color on selected cells in my active workbook.
    So I dont understand why its trying to open the template with the macro code I posted earlier.
    We understand all that, but you need to get rid of what ever is causing the REF# errors


    As I said before, without the TEMPLATE,xltm it's hard to see what is going on
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  12. #12
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    OK. Heres the "master" I want to have the user to open, and then save as "whatever".
    Attached Files Attached Files

  13. #13
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    Quote Originally Posted by chapel View Post
    OK. Heres the "master" I want to have the user to open, and then save as "whatever".
    1. Excel has an Excel definition of 'template' -- it's an .xltm or .xlts file. Just calling it a template doesn't make Excel think it's a XLTM file

    Capture.JPG

    2. I deleted all the REF# ranges since they were not doing anything anyway and saved your file as an XLTM file

    3. Double clicking the XLTM creates a new file

    4. The macros work without opening the original template file

    5. The created file (whatever.xlsm) must be saved by the user as an XLSM file

    Note XLTM files are not permitted to be uploaded, so save MASTER TIDSREGISTRERING2.xltm.zip and delete the .zip extension, then double click it
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  14. #14
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    Hi Paul!
    thank you for your efforts.
    I must be doing something wrong, because I cannot get this to work.
    So I did this:
    downloaded your edited file. (the zip file)
    deleted the zip-extension
    opened the file and saved it under a new name.
    closed the files
    opened the new file
    selected cells and activated the macro (change color to blue)
    color changed - but the "template file" you created still opens?

  15. #15
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    5. The created file (whatever.xlsm) must be saved by the user as an XLSM file
    How did you open the files?

    Did you save it as a XLSM file?

    So I did this:
    OK - downloaded your edited file. (the zip file)
    OK - deleted the zip-extension

    Double click the un-zipped file XLTM file without opening it.

    Save the file it creates under a new name, make sure it's macro enabled XLSM file
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  16. #16
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    Yes, saved as xlsm.
    The files that opens "unintentionally" is "MASTER TIDSREGISTRERING2.XLSB"

  17. #17
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    OK

    Try opening the XLSB file and then FileSaveAs it an XLTM file like my picture in Post #13

    Then double click the XLTM file

    If that doesn't work, then I'm really stuck
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  18. #18
    VBAX Regular
    Joined
    Dec 2015
    Posts
    15
    Location
    i guess we're stuck, cause this didnt work either
    But thanks for your time and efforts.
    Cheers,Chapel

  19. #19
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,290
    Location
    Did you try looking at the suggestion in post 10?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

  20. #20
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,856
    Location
    Quote Originally Posted by chapel View Post
    i guess we're stuck, cause this didnt work either
    But thanks for your time and efforts.
    Cheers,Chapel
    Did you delete all the lines causing REF# errors in Post#5 before you saved the XLSB as an XLTM?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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