+ Reply to Thread
Results 1 to 10 of 10

"An error has occurred" when running a macro

  1. #1
    Registered User
    Join Date
    05-30-2008
    Posts
    64

    "An error has occurred" when running a macro

    Hi,
    I am trying to run a macro and keep getting a error message saying "An error has occurred". The macro copies some existing worksheets into a new worksheet. I have tried it on my colleagues' PCs and it works without a problem. I have checked the Excel settings and theyre the same as mine.

    The code crashes at this line:

    ThisWorkbookName = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    ThisWorkbook.Worksheets("1) Intro").Copy

    Is there an obvious setting I haven't enabled that could cause this error?
    Thanks

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,464

    Re: "An error has occurred" when running a macro

    ThisWorkbookName is just a string variable.

    Change to
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: "An error has occurred" when running a macro

    Hi Ezzy,
    First I would like to know why you have assigned the variable ThisWorkbookName to ActiveWorkbook.Name and then in the 3rd line you don't use that variable?
    In my opinion this looks kinda redundant since ThisWorkbook.Worksheets("1) Intro").Copy and ActiveWorkbook.Worksheets("1) Intro").Copy is the same thing.

    Please Login or Register  to view this content.
    This part of the code would do just fine. Try and see by removing the 1st line of code and leaving just the 2.

    Please Login or Register  to view this content.
    Another thing you could do is use this line of code but BE CAREFUL since you don't want to ignore something that could affect your output. This code is good to ignore errors but don't assume that ignoring errors is a good thing.

    Please Login or Register  to view this content.
    Thanks,
    Fonzie

  4. #4
    Registered User
    Join Date
    05-30-2008
    Posts
    64

    Re: "An error has occurred" when running a macro

    Thanks for the suggestions. I tried all the options above and still get the same error.

  5. #5
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: "An error has occurred" when running a macro

    Ezzy,

    What excel settings have you checked?

    thanks,
    Fonzie

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,464

    Re: "An error has occurred" when running a macro

    Then need to see your full code and don't forget to wrap the code with the code tag.

    e.g
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]

  7. #7
    Registered User
    Join Date
    05-30-2008
    Posts
    64

    Re: "An error has occurred" when running a macro

    Quote Originally Posted by fonzie29 View Post
    Ezzy,

    What excel settings have you checked?

    thanks,
    Fonzie
    I went into Options > Save and then went through all the Trust Centre settings.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,572

    Re: "An error has occurred" when running a macro

    Your variable names are confusing. You should use something more descriptive. Try something like:
    Please Login or Register  to view this content.
    Ben Van Johnson

  9. #9
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: "An error has occurred" when running a macro

    So you haven't looked at the Macro settings?
    You can get there by holding Alt + L + AS check to see what your settings are.

    Thanks,
    Fonzie

  10. #10
    Registered User
    Join Date
    05-30-2008
    Posts
    64

    Re: "An error has occurred" when running a macro

    yes, I had a look at the macro settings too.

+ 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] Excel Crashes or Gives "Automation Error" on Mac when running Macro
    By mlj61289 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 04:39 PM
  2. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  3. Macro Error with code "Range("A65536").End(xlUp).EntireRow.Insert"
    By lukasj13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2010, 08:48 PM
  4. "400" error when running macro
    By jasonp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2010, 09:45 AM
  5. "Clean Me" Macro is giving "#VALUE!" error in the Notes field.
    By Ryan Watkins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2005, 08:05 PM

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