+ Reply to Thread
Results 1 to 6 of 6

Application.MoveAfterReturnDirection - Capturing cursor move direction

  1. #1
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    140

    Application.MoveAfterReturnDirection - Capturing cursor move direction

    Hello,

    I have the following scrip that runs when the workbook is opened....
    Please Login or Register  to view this content.
    and then the following that runs when the workbook is closed....
    Please Login or Register  to view this content.

    This workbook I have contains VBScript that rely's on the cursor movement going to the right (or staying on the same line as the cell that has just been modified).
    On opening the workbook I am trying to capture the cursor movement in a variable then change the direction to <right>, on closure of the workbook it uses the variable to change it back to what it was.
    The changing of direction to <right> is working but when I close the workbook it is changing the direction to <left> which isn't correct (for my tests I have been setting the cursor direction to <down>).

    Please can someone help. Thanks.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Application.MoveAfterReturnDirection - Capturing cursor move direction

    Use the BeforeSave Event rather than the BeforeClose Event.
    Gary's Student

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Application.MoveAfterReturnDirection - Capturing cursor move direction

    Hi, Marc,

    CursorMove is a local variable known for Workbook_Open but unknown to Workbook_BeforeClose. You would need to make it a global variable (Public in a standard module). And AFAIR these values are of Type Long, not of String.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    HTH,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Application.MoveAfterReturnDirection - Capturing cursor move direction

    why does your code rely on the cursor direction?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    140

    Re: Application.MoveAfterReturnDirection - Capturing cursor move direction

    Jakobshavn : I thought about the 'BeforeSave' option a user may go into the Workbook and then exit without saving so didn't think this option would work.

    JosephP : I'll answer so that I don't appear rude. I have am using the 'Selection.Offset' command to automatically add contents and data validation to the same line depending on what the user enters in certain cells. If the cursor moved away from the line that the edited cell was on it messed things up.

    HaHoBe : This worked, thank you.


    Thanks to you all for getting back to this thread so quickly :-D

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Application.MoveAfterReturnDirection - Capturing cursor move direction

    if you are using a worksheet_change event to add the validation you can use the Target argument, which refers to the changed cell, rather than rely on the currently selected cell

+ 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. Change cursor direction per sheet
    By aarzu.maknojia in forum Excel General
    Replies: 3
    Last Post: 06-05-2012, 12:06 AM
  2. CURSOR DIRECTION AFTER POSTING
    By tom in forum Excel General
    Replies: 1
    Last Post: 11-05-2005, 07:35 PM
  3. Control cursor direction in highlighted group of cells/Page setup
    By George Tung in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 09-06-2005, 07:05 AM
  4. Replies: 1
    Last Post: 08-26-2005, 03:05 PM
  5. Changing direction of cursor after hitting enter - toggling with toolbar macro??
    By StargateFan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-09-2005, 09:06 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