+ Reply to Thread
Results 1 to 6 of 6

Extremely simple macro wont work

  1. #1
    Registered User
    Join Date
    05-10-2006
    Posts
    7

    Extremely simple macro wont work

    Can anyone please tell me why the following wont work?????

    Private Sub Workbook_Open()
    If Sheet1("B2") = "4" Then Application.Run ("MTEmailer")
    End Sub

    Sheet1 contains this:
    - The formulas are in column B
    1 Todays Date: =TODAY()
    2 Todays Day: =WEEKDAY(B1,2) <--which is 4

    The MTemailer macro itself works fine but it wont run based on the condition in B2... so simple yet it just wont do it for me.

    Please help!!
    Thanks in advance,
    Tane
    Last edited by tanewha69; 08-30-2006 at 07:22 PM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    The error is that in B2 you have a value
    Your If statement is testing for text

    Sheet1("B2") = "4"
    is not the same as
    Sheet1("B2") = 4

    another suggestion

    If B1 is always displays todays date and B2 always displays the Weekday number of todays date why not use this line of code

    If Weekday(Now()) = 4 Then Application.Run ("MTEmailer")

  3. #3
    Registered User
    Join Date
    05-10-2006
    Posts
    7
    Thanks for your suggestion, I have tried it with and without the quotation marks and neither work... I will try the other piece of code and see how that goes.
    Cheers
    Tane

  4. #4
    Registered User
    Join Date
    05-10-2006
    Posts
    7
    Hi there,
    I tried the suggested formula but nothing happened... considering this one didn't work and my one above didn't either am I putting it in the right place? Something is just not right, both the above codes should work but its just not activating them when I open the workbook when it should be!!!???? Maybe I should just throw it out the window, at least that will make me feel better.

  5. #5
    Registered User
    Join Date
    05-10-2006
    Posts
    7
    Ok, I got it going by changing the 4 to 5!? Considering its Thursday where I am 5 should be Friday but it activates on thursday... is there a variable that tells me what day of the week is 1, 2, etc.. ??

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this VBA code

    MsgBox Weekday(Now()) this gives the same result as using =WEEKDAY(B1,1) formula

    Sunday = 1
    Monday = 2
    Tuesday = 3
    Wednesday = 4
    Thursday = 5
    Friday = 6
    Saturday = 7

    Which is a different result you get from using =WEEKDAY(B1,2) on a spreadsheet.

    I have never used the Weekday formula and was not aware that you alter the result based on the ,2

+ 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