By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Pop open form when opening a spreadsheet

P: 1
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.

Apr 27 '07 #1
Share this Question
Share on Google+
3 Replies

P: 29
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:

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  2. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  4. Dim hwndFound As Long   'The window handle
  6. Private Sub Timer1_Timer()
  8.     'Get the handle of the application if it is open
  9.     hwndFound = FindWindow(vbNullString, "Microsoft Excel - Book1")
  11.     If hwndFound Then
  12.         Me.Show
  13.         SetForegroundWindow Me.hwnd
  14.     End If
  16. End Sub
Apr 28 '07 #2

Expert 5K+
P: 8,434
Is this a separate VB program, or is it written as a VBA macro in Excel?
Apr 29 '07 #3

P: 29
It's a VB program that runs hidden in the background with a timer. Good question, though.
Apr 30 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.