+ Reply to Thread
Results 1 to 13 of 13

Run macro after opening the file at the first time only

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Run macro after opening the file at the first time only

    Hello Friends,
    I want to run a macro only at the first time opening the file in a day. Doesn't matter what time it is. It should run only first time when I open the file in a day. After that it should run next day only.

    Please provide me code for it. I use call event but the macro runs each time I open the file which is very annoying.

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Run macro after opening the file at the first time only

    This checks if the date in cell A1 is the same as the current date. If not, it runs your macro and sets the date in A1 to the current date.

    Private Sub Workbook_Open()
        With Sheets("Access").Range("A1")
            If .Value < Date Then
                Call Sort
                MsgBox "Welcome!"
                .Value = Date
            End If
        End With
    End Sub
    Last edited by AlphaFrog; 07-13-2013 at 10:51 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-11-2013
    Location
    South Africa, De Aar
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Run macro after opening the file at the first time only

    Awesome stuff and oh so simple actually.
    Great addition for " beautifying" Excell or most spreadsheet programs for the user.
    If I were to use a macro to run a start up screen once daily using this code...what can be included in the start up screen?
    Welcome message /Today's date and time displayed with something like a widget / calendar info or reminders...?
    Could this macro pull this info from a central file over a local network that can be edited daily?

    Waves

  4. #4
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Dear AlphaFrog,
    Thank you. It's working fine. I want to run a second macro after this one 'Sort'. After sort macro I want to run 'Company' macro automatically. Solution please! I want to run this two macros automatically one after one once at the time of first opening the file in a day.

    Mukesh
    Attached Files Attached Files
    Last edited by mukeshbaviskar; 07-15-2013 at 12:08 PM. Reason: Attach attachment

  5. #5
    Registered User
    Join Date
    06-05-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    90

    Re: Run macro after opening the file at the first time only

    Sub main()
        Call Sort
        Call Company
    End Sub
    I would just make sure that you put the code given to you earlier into Company as well, or take it out of Sort and put it into this one.

  6. #6
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Hello bcas77,
    It's not working. Please fine the mistake and give me a solution.

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Run macro after opening the file at the first time only

    After Call Sort, add the line Call Company

    Private Sub Workbook_Open()
        With Sheets("Access").Range("A1")
            If .Value < Date Then
                Call Sort
                Call Company
                MsgBox "Welcome!"
                .Value = Date
            End If
        End With
    End Sub

  8. #8
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Hello AlphaFrog,
    It's not working. Please see the attached file and find the solution.

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Run macro after opening the file at the first time only

    Put any date previous to today's date in sheet Access cell A1. Do not use the =TODAY() formula. Put an actual date previous to today. Save the workbook, close, then reopen it to trigger the macros.

    The code triggers when cell A1's date is less than the current date. The code will update cell A1 with the current date when it runs.

  10. #10
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Hello AlphaFrog,
    Excellent! It's working fine. Now my problem is solved.

    Thank you for guidance.

    Mukesh

  11. #11
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Hello AlphaFrog,,
    One more modification required. I want to run a macro 'selection' each time I open the file in a day. After opening the file the focus should be on search sheet cell 'c4' to search new contact details. I create a workbook open event but it gives a error of ambiguous name detected. How to solve it?

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Run macro after opening the file at the first time only

    Private Sub Workbook_Open()
        With Sheets("Access").Range("A1")
            If .Value < Date Then
                Call Sort
                Call Company
                Application.Goto Sheets("Search").Range("C4")
                MsgBox "Welcome!"
                .Value = Date
            End If
        End With
    End Sub

  13. #13
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Run macro after opening the file at the first time only

    Hello AlphaFrog,
    Thank you for solution.

    Mukesh

+ 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. Clear Data on first time opening file
    By jghender in forum Excel General
    Replies: 1
    Last Post: 01-16-2013, 03:47 PM
  2. Opening Excel and a specific file at the same time
    By HitTheEXCELerator in forum Excel General
    Replies: 4
    Last Post: 08-27-2011, 08:24 AM
  3. Replies: 12
    Last Post: 06-07-2011, 04:17 AM
  4. Opening files macro help (forcing directory, opening a tsv file)
    By NukedWhale in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2010, 03:07 PM
  5. Issue with Run Time Error when opening file
    By Sandy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-03-2006, 08:20 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