Create floating shape that stays visible on top of page when scrolling

LRATOZ

Board Regular
Joined
Aug 17, 2014
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a button on top of each sheet and when clicked takes the user back to the TOC.

HTML:
'Create & Position Shape
        Set Shape = Worksheet.Shapes.AddShape(msoShapeRoundedRectangle, 550, 0, 40, 20)

I've added following code so that the shape stays in the exact same position when the user irregardless of column width:

HTML:
'Prevent that shape moves whilst adding/deleting or re-sizing columns
        With Shape
        .Placement = xlFreeFloating
        End With

This works great however the button is fixed on top of the page and when scrolling up and down the shape disappears.
Is there a way that I can keep the shape on top of the page irregardless the scroll position?

I don't want to use the "Freeze the first row" or floating forms technique.

I am using Excel 2016

Many thanks in advance for your help.
Cheers,

Luke
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
.
Paste this into a regular module :

Code:
Option Explicit


Private eTime
Sub ScreenRefresh()
    With ThisWorkbook.Worksheets("Sheet1").Shapes(1)
        .Left = ThisWorkbook.Windows(1).VisibleRange(2, 2).Left
        .Top = ThisWorkbook.Windows(1).VisibleRange(2, 2).Top
    End With
End Sub


Sub StartTimedRefresh()
    Call ScreenRefresh
    eTime = Now + TimeValue("00:00:01")
    Application.OnTime eTime, "StartTimedRefresh"
End Sub


Sub StopTimer()
    Application.OnTime eTime, "StartTimedRefresh", , False
End Sub


Paste this into ThisWorkbook Module :

Code:
Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub


Private Sub Workbook_Open()
StartTimedRefresh
End Sub

The first macro is set for Sheet1. You'll need to paste an ActiveX CommandButton on Sheet1.
 
Upvote 0
.
Paste this into a regular module :

Code:
Option Explicit


Private eTime
Sub ScreenRefresh()
    With ThisWorkbook.Worksheets("Sheet1").Shapes(1)
        .Left = ThisWorkbook.Windows(1).VisibleRange(2, 2).Left
        .Top = ThisWorkbook.Windows(1).VisibleRange(2, 2).Top
    End With
End Sub


Sub StartTimedRefresh()
    Call ScreenRefresh
    eTime = Now + TimeValue("00:00:01")
    Application.OnTime eTime, "StartTimedRefresh"
End Sub


Sub StopTimer()
    Application.OnTime eTime, "StartTimedRefresh", , False
End Sub


Paste this into ThisWorkbook Module :

Code:
Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub


Private Sub Workbook_Open()
StartTimedRefresh
End Sub

The first macro is set for Sheet1. You'll need to paste an ActiveX CommandButton on Sheet1.
This is awesome. I used it for a normal Grouped shape also and works perfectly. Thanks for this.

J
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top