View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Hendri Adriaens Hendri Adriaens is offline
external usenet poster
 
Posts: 5
Default programming button again

I pasted the code that I use below.

Sorry, it was missing. Here it is:

Private Sub Add_start_button(cl)
Dim VBEHwnd As Long
Dim StartLine As Long
Dim cmdBtn As CommandButton
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk",
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
Set cmdBtn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=Range(cl).Left + 1, Top:=Range(cl).Top + 1, Width:=130,
Height:=24).Object
cmdBtn.Caption = "Ga naar startpagina"
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet. Name).CodeModule
StartLine = .CreateEventProc("Click", "CommandButton1") + 1
.InsertLines StartLine, "Sheets(""Start"").Activate"
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub

and at the start of the module, we have:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hWndLock As Long) As Long

-Hendri.