+ Reply to Thread
Results 1 to 14 of 14

Macro that AUTOMATICALLY activates another macro without human interference? HELP

  1. #1
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Hi Guys.

    I've been creating a macro for my (small) investment team, but I'm struggeling to get the final touch to work. The macro just updates certain cells which contains a function that get (almost) real-time quotes from Yahoo finance. When the cells is updated the macro prints the total portfolio value to another sheet along with date and time. Simple as that. The problem is that some of my stocks is bought in another stock exchange which closes at another time of the day. In other words, I have to create a macro that automatically activates the above-mentioned macro at a certain time of the day (23.59). I've tried alot and my macro ONLY works if i press F5 before i leave work, but I want this update to happend every night without me interfering each day. Below you can se all the codes (ps. if you have any tips to make it better I would appriciate it).

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

    I have never written a macro before, so the macro above is creatied through googling and trying/failing.

    Best regards
    Thomas Mangor-Jensen
    Last edited by Mangorni; 04-29-2016 at 05:39 AM. Reason: Tips from another forum user.

  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,613

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Hi Thomas,

    Where you've placed all these codes. To work properly some pieces shall be in standard module (like your knappen macro), other in Thisworkbook module (Private Sub Workbook_Open()) and some in a worksheet code (Private Sub Worksheet_Activate() or Change )

    The next point is - please edit your post and use code tags - it increases readability of the code and is required by our http://www.excelforum.com/forum-rule...rum-rules.html
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Thanks for the quick reply Kasper. I have now edited the post and uses code tags.

    "Knappen" is placed in Module2, while the rest is placed in sheet7 (MLC) which is were the stock prices are.

    I haven't quite understood were i should place each of the codes. Is there a simple rule or something I can follow?

    Anyways, the code works pretty fine, except for the fact that it need human interference every day (me to press F5 in the last sub).

    thanks

  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,613

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Please Login or Register  to view this content.
    shall be in thisworkbook code. In VBA Editor (Alt+F11) click on the list of your workbook objects on ThisWorkbook (could be also translated - in PL versions since Excel 2007 it's called Then_Skoroszyt - which means thisworkbook anyway :-P) to open it's code

    PS. To attach a sample workbook click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window. Select files (max 2) press Upload and press Close then Submit reply
    Attached Images Attached Images
    Last edited by Kaper; 04-29-2016 at 06:20 AM.

  5. #5
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Ok, I have pasted the last code into "ThisWorkbook", so now it should run "knappen" every day (except from weekends) at 23.59 without any human interference?

    If so, thank you very much! I will respond to this thread on monday when I will know the answer.


    Anyhow, suddenly my "Stockquote-function" stopped working? I have attached the excel sheet.

    Thank you in advance.


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

  6. #6
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    The stockquote-function suddenly started working again, so now I just have to wait and se if oyur answer does the trick.

    Thank you, Kaper!

  7. #7
    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,613

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    As for the OnTime - as you see it is called when workbook is open.
    If you closed the file and then opened it system scheduler shall have knappen planned on 23:59 today. But note that if you do not open file again, nothing will be scheduled for monday 23:59, Tuesday 23:59 etc.

    Plying with OnTime is always a bit delicate, but you coukld try to include next OnTime call inside knappen itself:

    Please Login or Register  to view this content.
    the second question - at the moment I do not have time for detailed investigation. May be you simply face some problems with internet connection?

  8. #8
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    I managed to fix the other question.

    Well, there you at least solved why the macro won't update automatically! This spreadsheet is (almost) never closed! As I understand from your answer the spreadsheet has be reopened to reactivate the macro, right?

    So now, if I use the above-mentioned code, the "update-at-23.59-macro" will activate whenever I push the button that is linked to "knappen"-macro?

    But is there a way to keep reactivating the "update-macro" each day without reopening the spreadsheet?

    Thomas

  9. #9
    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,613

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    If the file is always open, the code from post #7 once executed once, shall run every day and if it is not weekend, do what is within the body and if it is weekend just schedule next check on next day a minute before midnight.

  10. #10
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    For the first time, the macro was put on a real test while I was on vacation. Well, it failed.

    For some reason the macro inserted values for saturday and sunday, but stopped after that. So when I got home a whole week of data was missing from my spreadsheet.

    I've tried intensely to find the error, but I cannot find it. I figured the error has to be in the below-mentioned code?

    Please Login or Register  to view this content.
    Thanks for any response.

    Thomas

  11. #11
    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,613

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Probably the algorithm shall be:

    check if it is a week day
    if so do weekday tasks and schedule next execution
    if not then just schedule next execution

  12. #12
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    remove the Application on time from the knappen Function and maybe use this format cause its shorter and easier to read

    Please Login or Register  to view this content.
    Then put this in ThisWorkbook
    Like this it restarts the Timer only if iths saturday or sunday and does also start knappen on the other days
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Thanks again for the help, but the macro won’t work and the problem is still the same.

    I went on a long weekend, so it was a good test on the “new” code. However, when I got back to the office today my spreadsheet was missing values for Friday.

    The code is supposed to run every day, accept in the weekends and the only human interaction should be a click on the button on Monday morning.

    I can’t understand why the code stops running after printing my values on Thursday.

  14. #14
    Registered User
    Join Date
    02-24-2016
    Location
    Oslo
    MS-Off Ver
    Office 365
    Posts
    59

    Re: Macro that AUTOMATICALLY activates another macro without human interference? HELP

    Thank you both, it now works perfectly!

+ 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. Replies: 1
    Last Post: 10-10-2015, 01:00 AM
  2. [SOLVED] Macro activates in wrong sheet
    By SoothSailor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2015, 12:17 PM
  3. Help with running a Macro that activates a different workbook whose name changes
    By jjcarter1988 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-24-2013, 05:45 PM
  4. Button who activates a macro
    By RoMarius1981 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-20-2012, 07:27 AM
  5. Cell select activates macro
    By pauluk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2005, 09:55 AM
  6. [SOLVED] How can I stop a macro for Human Interaction
    By Henry Stock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2005, 07:06 PM
  7. [SOLVED] Rectangle that activates a macro
    By in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2005, 03:06 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