+ Reply to Thread
Results 1 to 5 of 5

Macro only runs from inside sheet not from another workbook/module

  1. #1
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Macro only runs from inside sheet not from another workbook/module

    Hi,

    I have the following macro (not mine, but it works perfectly). The issue I have, is it only works when I embed it in the "Master" worksheet and run it. It won't work when called from another workbook. I am running a series of automated tasks, and this is the last one, so would just like it to happen, so I can automatically save afterward.

    If I run from somewhere other than from within the "Master" sheet, it does the first couple of rows, then when it hits a duplicate value, I get a 1004 error "Name already taken" here...

    "Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = shName"

    Any idea's anyone?

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,861

    Re: Macro only runs from inside sheet not from another workbook/module

    Two concepts - if you want to replace old sheet shname with a new empty one then:

    Please Login or Register  to view this content.
    if you want to keep it and work with a current one:
    on error resume next
    Please Login or Register  to view this content.
    and other combinations like if exists then rename as backup and then create new one etc.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Re: Macro only runs from inside sheet not from another workbook/module

    Unfortunately neither work. The first one results in the correct worksheets, and names, but only 1 row per sheet, deleteing all the rest.
    The second has again the correct sheets, but none of the rows correspond to the correct sheet.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,861

    Re: Macro only runs from inside sheet not from another workbook/module

    Try such change:
    Please Login or Register  to view this content.
    Because now, with Thisworkbook you refer to the workbook where macro resides.
    With ActiveWorkbook it will work on ... active one (not necserrily the one, where macro resides).

  5. #5
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Re: Macro only runs from inside sheet not from another workbook/module

    Perfect. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] AND formula does not work inside the macro module
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-30-2013, 08:49 PM
  2. Workbook opening when macro runs
    By Dubby20 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2012, 11:58 AM
  3. Macro that runs inside cell range selected
    By TrentSe7en in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-06-2010, 05:41 AM
  4. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  5. open workbook macro only runs once
    By Directlinq in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-30-2009, 07:44 AM
  6. Insert a new workbook with VBA code in the sheet module into existing macro
    By bobaftt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2009, 12:12 PM
  7. How to run a commandbar controled module inside a Macro
    By betty77 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2006, 10:29 AM
  8. [SOLVED] Before macro runs - check workbook name
    By Jan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-02-2006, 09:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1