+ Reply to Thread
Results 1 to 6 of 6

Workbook_activate - why doesn't it work

Hybrid View

Lv27 Workbook_activate - why... 05-01-2012, 06:53 AM
marreco Re: Workbook_activate - why... 05-01-2012, 07:11 AM
TMS Re: Workbook_activate - why... 05-01-2012, 07:15 AM
Lv27 Re: Workbook_activate - why... 05-01-2012, 07:30 AM
TMS Re: Workbook_activate - why... 05-01-2012, 09:12 AM
Lv27 Re: Workbook_activate - why... 05-07-2012, 02:50 PM
  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    85

    Workbook_activate - why doesn't it work

    I put this in the "Workbook":

    Private Sub workbook_activate()
    alertTime = Now + TimeValue("00:00:10") 'delay for open indtil execute macro
    closingTime = Now + TimeValue("00:00:15") 'delay fra open til close
    Application.OnTime alertTime, "EventMacro"
    
    If TimeSerial(6, 0, 0) < Now And TimeSerial(8, 0, 0) > Now Then
    Application.OnTime closingTime, "CloseMacro"
    End If
    End Sub
    
    Private Sub EventMacro()
    Range("a500000").End(xlUp).Select
    
    End Sub
    
    Private Sub CloseMacro()
    With ThisWorkbook
    .Save
    .Close
    End With
    End Sub


    -- But is says that "EventMacro" cannot run? Can anyone help me out?
    Last edited by Lv27; 05-07-2012 at 02:49 PM.

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Workbook_activate - why doesn't it work

    place the code inside (Alt + F11) and paste This_Workbook

    Private Sub workbook_activate()
    alertTime = Now + TimeValue("00:00:10") 'delay for open indtil execute macro
    closingTime = Now + TimeValue("00:00:15") 'delay fra open til close
    Application.OnTime alertTime, "EventMacro"
    
    If TimeSerial(6, 0, 0) < Now And TimeSerial(8, 0, 0) > Now Then
    Application.OnTime closingTime, "CloseMacro"
    End If
    End Sub
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Workbook_activate - why doesn't it work

    You should put your code in CODE tags. Please read the forum rules for clarification.

    While you are doing that, consider that you need to put the EventMacro and the CloseMacro in a standard module, not in the Workbook Class module.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    05-01-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Workbook_activate - why doesn't it work

    Tried putting "EventMacro" and "StandardMacro" in the standard module instead and now it works! Thank you Will read the forum rules... Am new here

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Workbook_activate - why doesn't it work

    You're welcome. And welcome to the forum! Please add code tags to the original post as, otherwise, the moderators could reprimand us both

  6. #6
    Registered User
    Join Date
    05-01-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Workbook_activate - why doesn't it work

    Haha we definitely can't have that - I have added the code tags as requested

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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