+ Reply to Thread
Results 1 to 12 of 12

Running a macro but it crashes and closes

  1. #1
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Running a macro but it crashes and closes

    Hi All,

    Hoping to seek help from all of you. I'm running a macro where it downloads a file from SAP and copies the data to an existing template. But the existing template crashes and closes. Please help me resolve the issue with the codes below. I think it's closing because the macro is confused with some of the codes. However, I'm not sure what code to replace it with. Thank you in advance.

    Please Login or Register  to view this content.
    Last edited by louise_newbie13; 05-28-2021 at 03:41 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Running a macro but it crashes and closes

    Administrative Note:

    Hi Louise, welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    done thank you.

  4. #4
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Running a macro but it crashes and closes

    Hello Louise,

    Awesome that you are starting to code in VBA, you will quickly learn how much you can do with it.

    It is important that you early learn how to not use the .Activate, .Select

    Instead define your workbooks and worksheets as objects.

    Please Login or Register  to view this content.
    And set them to the values that you need...
    Please Login or Register  to view this content.
    ... inorder to do what you need.
    Please Login or Register  to view this content.
    By doing this your code will be more clear and it will be easier to not make mistakes. it is possible that your issue lies within this...

  5. #5
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    Quote Originally Posted by MrChulo View Post
    Hello Louise,

    Awesome that you are starting to code in VBA, you will quickly learn how much you can do with it.

    It is important that you early learn how to not use the .Activate, .Select

    Instead define your workbooks and worksheets as objects.

    Please Login or Register  to view this content.
    And set them to the values that you need...
    Please Login or Register  to view this content.
    ... inorder to do what you need.
    Please Login or Register  to view this content.
    By doing this your code will be more clear and it will be easier to not make mistakes. it is possible that your issue lies within this...
    ohhh thank you I will try it now. Thank you very much!

  6. #6
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Running a macro but it crashes and closes

    Hi Again,

    Translating your code to this way of working, I think I found the problem, or at least it is not clear to me where the source Worksheet is/should be defined... I have assumed that it is sheet1 in worbook main in my code below.

    This is not tested of course, but hopefully it is pointing you to the right direction.

    Please Login or Register  to view this content.
    Good luck!

  7. #7
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    Quote Originally Posted by MrChulo View Post
    Hi Again,

    Translating your code to this way of working, I think I found the problem, or at least it is not clear to me where the source Worksheet is/should be defined... I have assumed that it is sheet1 in worbook main in my code below.

    This is not tested of course, but hopefully it is pointing you to the right direction.

    Please Login or Register  to view this content.
    Good luck!
    hi there, thanks a lot for giving these codes to me. However, when it comes to clearing the sheets, it doesn't go to the sheets anymore and nothing happens. ;'( do you have any idea why? thank you for your help again

  8. #8
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Running a macro but it crashes and closes

    Please attach you file so that I understand better.

  9. #9
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    is it okay to copy paste all the codes of that module instead of the file? I'm afraid there are many confidential data.

  10. #10
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    Quote Originally Posted by MrChulo View Post
    Please attach you file so that I understand better.
    In case all the codes of the module should be fine, I'm putting it here. thank you

    I changed something in the codes you gave a while ago because the main should be the existing template and where the data should be copied in the main is on Sheet 2. Whereas the target is the new file where the data is coming from.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Running a macro but it crashes and closes

    I need to understand how your sheets look like, not the code.

    The code I put to clear the content should be fine... the code does not have to "go to the sheet" this is the point of not activate and Select.

  12. #12
    Registered User
    Join Date
    05-27-2021
    Location
    Manila, Philippines
    MS-Off Ver
    Microsoft Excel 365
    Posts
    8

    Re: Running a macro but it crashes and closes

    Quote Originally Posted by MrChulo View Post
    I need to understand how your sheets look like, not the code.

    The code I put to clear the content should be fine... the code does not have to "go to the sheet" this is the point of not activate and Select.
    yeah I understand. But the template has very confidential data as this is a template I use at work. I'm afraid I cannot share it here. But thank you for all your help.

+ 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. Macro that worked fine, now crashes after running macro on new laptop/installation
    By mastermind85 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-09-2017, 12:53 PM
  2. [SOLVED] When running a Macro, it crashes my Excel 2013... Why?
    By fleyd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2015, 11:50 AM
  3. Excel crashes erratically after running a macro
    By David A Coop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-20-2014, 11:56 PM
  4. VBA macro running in XP crashes in Windows 7
    By sadarudeen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2013, 01:08 PM
  5. Excel Crashes when saving after running macro
    By msmithdynamicsgp in forum Excel General
    Replies: 0
    Last Post: 10-24-2011, 12:16 PM
  6. Error occurs, excel closes when running macro?
    By danny2000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2008, 06:45 AM
  7. Excel crashes after running Macro
    By sjl17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-25-2005, 06:27 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