+ Reply to Thread
Results 1 to 8 of 8

Center Cursor on Button Click

  1. #1
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Center Cursor on Button Click

    Hi I posted something similar a while back. I found a solution, but it requires me to turn off freeze panes and jump through quite a few hoops. I was wondering if anyone had any thoughts on getting this to work more smoothly

    Current Solution:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Center Cursor on Button Click

    Trying to use something similar to the following such that the cursor position is accounted for given the location of the Freeze Panes, but I some how just keep getting solely the Pane location

    Public Sub FindMyCenter2()
    Application.EnableEvents = False

    Dim o As Object
    Dim wnd As Window

    Set o = TESTING.OLEObjects("SectionToggle")
    Set wnd = o.TopLeftCell.Parent.Parent.Windows(1)


    Set PvsCell = ActiveCell
    TESTING.Activate



    For i = 1 To wnd.Panes.Count
    If Not Intersect(o.TopLeftCell, wnd.Panes(i).VisibleRange) Is Nothing Then

    TOGGLESIDE.Left = PixelsToPoints(wnd.Panes(i).PointsToScreenPixelsX(o.TopLeftCell.Left))
    TOGGLESIDE.Top = PixelsToPoints(wnd.Panes(i).PointsToScreenPixelsY(o.TopLeftCell.Top))

    TOGGLESIDE.Right = o.TopLeftCell.Width * wnd.Zoom / 100 + TOGGLESIDE.Left
    TOGGLESIDE.Bottom = o.TopLeftCell.Height * wnd.Zoom / 100 + TOGGLESIDE.Top

    SetCursorPos TOGGLESIDE.Left, TOGGLESIDE.Top

    End If
    Next


    End Sub

  3. #3
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Center Cursor on Button Click

    Previous post https://www.excelforum.com/excel-pro...n-click-3.html

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Center Cursor on Button Click

    Eh, getting what to work more smoothly?
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Center Cursor on Button Click

    Hey Norie, long time, hope all is well. I'm trying to get the button coordinates without having to turn freeze panes on and off.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Center Cursor on Button Click

    Where is the button located?

    You mention freeze panes so that indicates that the button is on a worksheet.

    If that's the case couldn't you use it's TopLeftCell property to determine it's location and then use that in some way?

  7. #7
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Center Cursor on Button Click

    Yep it's on the spreadsheet. But I'm trying to keep the cursor center of the button on button press.

  8. #8
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Center Cursor on Button Click

    Every now and again, there's a simple thing we make difficult. Here's the solution.

    Declarations
    Please Login or Register  to view this content.

    Housekeeping:
    Please Login or Register  to view this content.
    Code:
    Please Login or Register  to view this content.
    Use to get to Location:
    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 02-27-2017, 09:17 AM
  2. Spreadsheet turns black when I click on merge&center
    By Swisski in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-11-2016, 04:15 PM
  3. Button Click on Spreadsheet commanded by Button Click on Userform
    By Quilie19 in forum Excel Programming / VBA / Macros
    Replies: 33
    Last Post: 04-07-2015, 11:35 PM
  4. [SOLVED] click on a color button and after button click it will color entire row of cell you click
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2014, 06:06 PM
  5. Merge and Center Multiple Cells with the same data with a button click
    By caliskier in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2012, 06:01 PM
  6. vba code for moving the cursor/right click/left click of the mouse?
    By yellowpower in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2010, 10:07 AM
  7. Move the cursor to a cell in button click event
    By Man Utd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2005, 12:05 AM

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