remove captions excel 2010 64 bit

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
I use the following script on my home computer to remove captions, however I can not use it on my work computer which is excel 2010 64bit.
I found info on changing the script to prtsafe so I made all the adjustments but it still would not work, it kept getting stuck on the hwnd section even with ptrsafe and prt added.


Code:
Option Compare Text
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function FindWindow Lib "user32" _
                        Alias "FindWindowA" (ByVal lpClassName As String, _
                                             ByVal lpWindowName As String _
                                             ) As Long
    
' Public Declare Function GetForegroundWindow _
   Lib "user32.dll" () As Long
Private Declare Function GetWindowLong Lib "user32.dll" _
                         Alias "GetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long _
                                                 ) As Long
     
Private Declare Function SetWindowLong Lib "user32.dll" _
                         Alias "SetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long, _
                                                 ByVal dwNewLong As Long _
                                                 ) As Long
    
Private Declare Function DrawMenuBar Lib "user32.dll" (ByVal hwnd As Long) As Long
    
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION = &HC00000
    
Function RemoveCaption3(ByVal hwnd As Long)
Dim BitMask As Long
Dim WindowStyle As Long
    
    WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
    BitMask = WindowStyle And (Not WS_CAPTION)
    Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
Function RestoreCaption3(ByVal hwnd As Long)
Dim BitMask As Long
Dim WindowStyle As Long
    
    WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
    BitMask = WindowStyle Or WS_CAPTION
    Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
'Example of Restoring Excel's Caption
Sub Restore_Windows_Caption()
RestoreCaption3 Application.hwnd
End Sub
    
Sub RestoreTitleBars()
Dim i As Long
Dim hwnd As Long
    
    For i = 0 To UserForms.Count - 1
        hwnd = FindWindow(vbNullString, UserForms(i).Caption)
        RestoreCaption3 Application.hwnd
    Next
End Sub

then in my userform I have the following.

Code:
Option Compare Text

Dim myClipbd As New DataObject
Private m_sngX As Single
Private m_sngY As Single
Option Explicit

Private Const MResizer = "ResizeGrab"
Private WithEvents m_objResizer As MSForms.Label
Private m_sngLeftResizePos As Single
Private m_sngTopResizePos As Single
Private m_blnResizing As Single

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' wait method for miliseconds sleep 500 = 1/2 a second
'Sleep 500

Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, ByVal lngWinIdx As Long, _
ByVal dwNewLong As Long) As Long

Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, ByVal lngWinIdx As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "user32" ( _
ByVal hwnd As Long, ByVal crKey As Integer, _
ByVal bAlpha As Integer, ByVal dwFlags As Long) As Long

Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC
Dim hwnd As Long

''''''''''''''''''''''
''''''''''''''''''''''
'MAKE SURE TO SET YOUR CAPTION PROPERTIES ON LEFT TO USERFORM NAM NOT BLANK
'OTHERWISE TITLE BAR WILL NOT REMOVE
''''''''''''''''''''''
''''''''''''''''''''''

Private Sub UserForm_Activate()
Dim lHwnd As Long
    lHwnd = FindWindow(vbNullString, Me.Caption)
    RemoveCaption3 lHwnd
 
In addition to PtrSafe, some of the Longs need to be LongPtr and the relevant variables need to be altered as well. Post back if you still get stuck, but this time post the amended code. ;)

Also, any chance you could tone down that signature pic - it's a bit much.
 
Upvote 0
Hi Rory,My code gets stuck on the following line at the getwindowlongptr, if I remove the ptr then it gets stuck at the hwnd.
Code:
 FWindowStyle = GetWindowLongptr(hwnd, GWL_STYLE)

full scripts follows

Code:
Option Explicit
    
Public Declare PtrSafe Function FindWindow Lib "user32" _
                        Alias "FindWindowA" (ByVal lpClassName As String, _
                                             ByVal lpWindowName As String _
                                             ) As LongPtr
    
' Public Declare Function GetForegroundWindow _
   Lib "user32.dll" () As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" _
                         Alias "GetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long _
                                                 ) As LongPtr
     
Private Declare PtrSafe Function SetWindowLong Lib "user32.dll" _
                         Alias "SetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long, _
                                                 ByVal dwNewLong As Long _
                                                 ) As LongPtr
    
Private Declare PtrSafe Function DrawMenuBar Lib "user32.dll" (ByVal hwnd As Long) As LongPtr
    
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION = &HC00000
    
Function RemoveCaption3(ByVal hwnd As LongPtr)
Dim BitMask As LongPtr
Dim WindowStyle As LongPtr
    
    WindowStyle = GetWindowLongptr(hwnd, GWL_STYLE)
    BitMask = WindowStyle And (Not WS_CAPTION)
    Call SetWindowLongptr(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
Function RestoreCaption3(ByVal hwnd As LongPtr)
Dim BitMask As LongPtr
Dim WindowStyle As LongPtr
    
    WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
    BitMask = WindowStyle Or WS_CAPTION
    Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
'Example of Restoring Excel's Caption
Sub Restore_Windows_Caption()
   RestoreCaption Application.hwnd
End Sub
 
Upvote 0
The function is Getwindowlong but hwnd should be declared as LongPtr everywhere.
 
Upvote 0
If you would like an introduction to the changes required, see

Office 2010 VBA


Hi Rory,My code gets stuck on the following line at the getwindowlongptr, if I remove the ptr then it gets stuck at the hwnd.
Code:
 FWindowStyle = GetWindowLongptr(hwnd, GWL_STYLE)

full scripts follows

Code:
Option Explicit
    
Public Declare PtrSafe Function FindWindow Lib "user32" _
                        Alias "FindWindowA" (ByVal lpClassName As String, _
                                             ByVal lpWindowName As String _
                                             ) As LongPtr
    
' Public Declare Function GetForegroundWindow _
   Lib "user32.dll" () As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" _
                         Alias "GetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long _
                                                 ) As LongPtr
     
Private Declare PtrSafe Function SetWindowLong Lib "user32.dll" _
                         Alias "SetWindowLongA" (ByVal hwnd As Long, _
                                                 ByVal nIndex As Long, _
                                                 ByVal dwNewLong As Long _
                                                 ) As LongPtr
    
Private Declare PtrSafe Function DrawMenuBar Lib "user32.dll" (ByVal hwnd As Long) As LongPtr
    
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION = &HC00000
    
Function RemoveCaption3(ByVal hwnd As LongPtr)
Dim BitMask As LongPtr
Dim WindowStyle As LongPtr
    
    WindowStyle = GetWindowLongptr(hwnd, GWL_STYLE)
    BitMask = WindowStyle And (Not WS_CAPTION)
    Call SetWindowLongptr(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
Function RestoreCaption3(ByVal hwnd As LongPtr)
Dim BitMask As LongPtr
Dim WindowStyle As LongPtr
    
    WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
    BitMask = WindowStyle Or WS_CAPTION
    Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
End Function
    
'Example of Restoring Excel's Caption
Sub Restore_Windows_Caption()
   RestoreCaption Application.hwnd
End Sub
 
Upvote 0
Thanks for the link Rory, however the script still does not work with changes made, I may have to keep searching the net for new working solutions.
 
Upvote 0

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