+ Reply to Thread
Results 1 to 9 of 9

Macro to move a shape once and move it back again on sequential presses.

  1. #1
    Registered User
    Join Date
    02-15-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    16

    Macro to move a shape once and move it back again on sequential presses.

    Hi all,

    Is it possible to write a macro that moves a shape to a certain location when a form button is pressed BUT then only move it back to its original position when the same form button is pressed? i.e. move a shape backwards and forwards between fixed locations on sequential presses?

    I can write a macro to move a shape once, but obviously, when i press it again, it moves the shape the same distance as it did the first time it was pressed.

    Any assistance would be very much appreciated.

    Cheers.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro to move a shape once and move it back again on sequential presses.

    You could record the position of the shape before it is moved and then move it back to that position after the button is pressed?

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to move a shape once and move it back again on sequential presses.

    Or have 2 shapes and switch the visible property:

    Please Login or Register  to view this content.

    The only advantage of this is you don't have to hard code the position into your vba.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to move a shape once and move it back again on sequential presses.

    Record the defaultposition of the shape in the shapeproperty 'alternativetext':

    Please Login or Register  to view this content.
    Create a Togglebuttons (ActiveX-control) in the sheet

    Use this code in the click-event of the togglebutton
    Please Login or Register  to view this content.
    Cfr. the attachment
    Attached Files Attached Files
    Last edited by snb; 12-13-2010 at 07:58 AM.



  5. #5
    Registered User
    Join Date
    02-15-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to move a shape once and move it back again on sequential presses.

    That is great help, thanks!

    Is it possible though to have multiple shapes toggle on and off and be linked to each other?

    i.e. i have a 50 question quiz and only want 10 questions to be viewed at any one time. Due to formatting issues with the s/s, hiding rows and columns is not possible, thus the easiest thing to do i believe is have shapes cover 40 questions at any one time. I was thinking that you may have 4 (or 5?) form buttons that once pressed expose a different set of 10 questions. Is this the right approach? Is it possible to use toggle buttons to do this as described above.

    Again, any assistance is appreciated. Thanks.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to move a shape once and move it back again on sequential presses.

    IMHO hiding the questions with shapes is probably over complicating the matter. Why not just have the font colour the same as the background of us a custom format of ;;; to hide what you don't want people to see. You can also use sheet protection to restrict what areas of the worksheet a user can select until required.

    Dom

  7. #7
    Registered User
    Join Date
    02-15-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to move a shape once and move it back again on sequential presses.

    Dom, How do i do that? i.e. "You can also use sheet protection to restrict what areas of the worksheet a user can select until required."?

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Macro to move a shape once and move it back again on sequential presses.

    PgDn to your next set of questions could be an option,
    or place a hyperlink at the 10th question and hyperlink to the next set of 10

  9. #9
    Registered User
    Join Date
    02-15-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to move a shape once and move it back again on sequential presses.

    Thanks Dave but not too sure that will work well. S/S is compact and having hyperlinks will wreck the formatting. Looking to also print the final result.

    I have attached the questionaire for reference. Looking to limit to single page view, i.e in this case 57 questions before moving onto 58-114 etc. In the attached file i have covered these questions with a shape and would like these to toggle on and off but would also look for the other quesions to toggle off sequentially.
    Attached Files Attached Files

+ 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