+ Reply to Thread
Results 1 to 16 of 16

Web Style 'Back' Button VBA Code

  1. #1
    Registered User
    Join Date
    07-20-2009
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    11

    Web Style 'Back' Button VBA Code

    Hi

    I have been trying to get a back button to work on an 2003 excel document that works like a website.

    In the web toolbar there is a facility to go back and forward (very much like using internet explorer). I want a button on the actual sheet that does this command. If i record a macro and click the web 'back' button it records the end result of the process, not the process itself -

    eg if sheet 1 and sheet 2 link to sheet 3 and I click a hyperlink from sheet 1 to sheet 3 then create a back button on sheet 3 and record a macro by clicking on the web toolbar back button the macro records the end result - eg Application.Goto Reference:="Sheet1!R14C8". However if i then go to sheet 3 through sheet 2, the back button I created takes me to sheet 1 not back to sheet 2.

    Anyone know the code I could use to make it actually go 'back' to the previous page?

    Any help would be greatly appreciated

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Web Style 'Back' Button VBA Code

    You'd need to use the workbook event to detect the sheet changing, and use that to store the most previous sheet, (either a single step or a list, depending what you want).
    Your 'Back' button would then have to reference that variable / list, to work out which sheet to go back to.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Web Style 'Back' Button VBA Code

    Try this to go to the previous sheet
    Please Login or Register  to view this content.
    This for the nxt sheet
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Web Style 'Back' Button VBA Code

    I don't think that is what is wanted, if I am understanding that macro correctly.

    Won't that just step backwards and forwards through the worksheets in the order they are in the workbook?
    I think the OP wants something that will step back through a 'History' of what sheets have been browsed.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Web Style 'Back' Button VBA Code

    A web back button steps back one page, you can't use the back button to jump back several pages. It's not 100% clear what the OP intends

  6. #6
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Web Style 'Back' Button VBA Code

    I haven't tried the code yet, but I think Roy's code would take you back and forth to previous or next sheet in order [sheet1, sheet2, sheet3 etc].

    I think the OP wants to go back to the sheet he came from. So, if you are on sheet 3 and go to sheet 7, then clicking the back button on sheet 7 would take you back to sheet 3. But if you were on sheet 1 and then got to sheet 7, clicking the same back button would take you to sheet1.

    I think you would have to create a list of sheets [history log] to keep track of previous sheets visited, so you can go back in that order.

    modytrane

  7. #7
    Registered User
    Join Date
    07-20-2009
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Web Style 'Back' Button VBA Code

    Thanks for the Replies

    Modytrane is correct - Roys suggestion simply moves to the previous or next sheet - Sheet 2 has Sheet 1 as previous and Sheet 3 as next. This is not however the sheet you were on previously. I need it to work like a web browser back button.

    How do i create a history log if that is needed?

    Is there not a simple way to tell the macro to do the process the web back button does in excel toolbar?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Web Style 'Back' Button VBA Code

    You need to capture the sheet before moving, unfortunately the Sheet deactivate event captures the active sheet which is the on you have moved to

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Web Style 'Back' Button VBA Code

    If the web toolbar back/forward button work as required try this which should give the save effect as clicking them.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,018

    Re: Web Style 'Back' Button VBA Code

    In case it's of interest, JKP has a free add-in called GoBack here that does this. The code is protected though, so you'd have to use it as is.
    Everyone who confuses correlation and causation ends up dead.

  11. #11
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Web Style 'Back' Button VBA Code

    I'm not sure if this is the best method, but it works.
    It will keep a history of '10', but you can change that by adjusting the red number.
    The code should be pasted into the 'ThisWorkbook' area of the VBAProject.

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

  12. #12
    Registered User
    Join Date
    07-20-2009
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Web Style 'Back' Button VBA Code

    Thanks for the help. Got it to work now.

    Used the simple command bar function Andy put up.

    Phil - thanks for the info on recording history - will come in handy for other work.

    Does anyone know of the command button IDs for the other buttons in Excel like this one? - application.CommandBars.FindControl(ID:=1017).Execute - is for the back button.

    Would be really useful to have :-)

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,018

    Re: Web Style 'Back' Button VBA Code

    This will list them on the active sheet:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-20-2009
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Web Style 'Back' Button VBA Code

    Thats great. Really useful

    Thanks

  15. #15
    Registered User
    Join Date
    11-19-2012
    Location
    south africa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Web Style 'Back' Button VBA Code

    Phil_V
    when you delete one of the worksheets that is in the history
    a "run-time error '424': object requires"

    how do I get past that?
    Thank you in advance!

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Web Style 'Back' Button VBA Code

    francoisehles,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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