+ Reply to Thread
Results 1 to 10 of 10

Auto add number when opening file

  1. #1
    Registered User
    Join Date
    04-11-2019
    Location
    Canada
    MS-Off Ver
    Mac2011
    Posts
    10

    Auto add number when opening file

    I am creating a purchase order template and want the Purchase Order (PO) number to automatically update by one when I open it. The code below is for a button that updates the number by one, then saves it so next time it will be updated. I want the macro do do the same thing, but automatically when I open the file so I don't have to press the button. I'm new to this, so I think I may have extra code in there, but it works.

    Please Login or Register  to view this content.
    Last edited by alansidman; 04-24-2019 at 10:33 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: Auto add number when opening file

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    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, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Auto add number when opening file

    Maybe this:


    Please Login or Register  to view this content.
    of course into Workbook code.
    Last edited by KOKOSEK; 04-24-2019 at 06:05 PM.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  4. #4
    Registered User
    Join Date
    04-11-2019
    Location
    Canada
    MS-Off Ver
    Mac2011
    Posts
    10

    Re: Auto add number when opening file

    That did not work

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: Auto add number when opening file

    Please explain what "doesn't work" means.
    • Does the code run?
    • Does it run but do nothing?
    • Does it produce error messages? If so, what do the messages say?
    • Does it produce unexpected/wrong results? If so, how do the results differ from what you expect?
    • Does it hang?

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Auto add number when opening file

    In addition to alansidman's questions, did you read the last sentence of KOKOSEK's answer on where to put the code?
    Did you also change the sheet reference?

  7. #7
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Auto add number when opening file

    @scottnunavut:
    If you original code works under button_click (You've said that), this should works as well.
    Of course, there are only changes on reference to sheet (Sheets("name")) as I don't know where locations of ranges are.

  8. #8
    Registered User
    Join Date
    04-11-2019
    Location
    Canada
    MS-Off Ver
    Mac2011
    Posts
    10

    Re: Auto add number when opening file

    Thanks for all you help but I've gotten nowhere. I've uploaded the file with the NEW PO button working. Again, when it is clicked, the number in D10 automatically +1 (moved it from 3 to 4), and then it saves so when I open it again it the number 4 is in D10. So, as is the file is usable, but it is more convenient to have the file auto +1 and then save so I don't have to remember click the button. thanks.
    Attached Files Attached Files

  9. #9
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Auto add number when opening file

    There is no code in Workbook code.
    It can't increment this value automatically if you do not put code where it should be put.

    Check attached file. It automatically increase D10 after each opening.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    04-11-2019
    Location
    Canada
    MS-Off Ver
    Mac2011
    Posts
    10

    Re: Auto add number when opening file

    GOT IT! Thanks all. Now how to I mark this thread as solved?

+ 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. Excel is auto-opening iqy file on open
    By Zacharyah in forum Excel General
    Replies: 2
    Last Post: 04-23-2020, 01:10 PM
  2. Auto Run macro when opening file
    By toci in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2015, 02:28 PM
  3. [SOLVED] VBA code for opening a file with a variable version number in the file name
    By trishcollins in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-04-2014, 04:38 PM
  4. [SOLVED] how to auto open file when opening another file
    By k1dr0ck in forum Excel General
    Replies: 2
    Last Post: 05-07-2012, 02:51 AM
  5. Auto update calculation upon opening file
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-16-2010, 11:41 AM
  6. Auto attach file after opening hyperlink
    By globalpontoon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2010, 03:14 PM
  7. auto prompt file insert object when opening a template
    By romeeko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2006, 10:45 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