Pop open form when opening a spreadsheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Matrix34
    New Member
    • Apr 2007
    • 1

    Pop open form when opening a spreadsheet

    This will be very simple basic coding to most of you, I'm just experimenting at the moment.

    I have created a form which I need to popup whenever my excel spreadsheet opens.

    Could someone provide me the code please, I've been trying all sorts.

    Cheers
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    #2
    In a timer, you could have it check for any window with a title "Microsoft Excel", then do whatever. Your code could look something like this:

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Dim hwndFound As Long   'The window handle
    
    Private Sub Timer1_Timer()
    
        'Get the handle of the application if it is open
        hwndFound = FindWindow(vbNullString, "Microsoft Excel - Book1")
        
        If hwndFound Then
            Me.Show
            SetForegroundWindow Me.hwnd
        End If
        
    End Sub

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Is this a separate VB program, or is it written as a VBA macro in Excel?

      Comment

      • cbbibleboy
        New Member
        • Apr 2007
        • 29

        #4
        It's a VB program that runs hidden in the background with a timer. Good question, though.

        Comment

        Working...