Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Automatically running an Excel macro on open once only


Hi guys,

Does anyone know of a way to automatically run a macro on open once
only? i.e. A user opens an excel worksheet, a macro is run prompting
them for some information, they save the file, re-open it however this
time it does not prompt for the questions? Please see below for my
macro. Any help would be greatly appreciated.


Sub Project()

Dim inputvar As String
Dim inputvar2 As String
Dim inputvar3 As String

inputvar = InputBox("Please Enter the Project Name?")
Range("b1") = inputvar

inputvar2 = InputBox("Please Enter the Start Date")
Range("b7") = inputvar2

inputvar3 = InputBox("Please Enter the Location")
Range("b8") = inputvar3

End Sub

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Automatically running an Excel macro on open once only

Hi David,

When you open the VBA editor, double click on ThisWorkbook in the project
explorer and paste this macro in there. It does run each time the workbook is
opened but after the data is in the cells it does not do anything and the
user would be unaware of it.

Private Sub Workbook_Open()
Dim inputvar As String
Dim inputvar2 As String
Dim inputvar3 As String

'Use code name for 1st sheet and this name does not
'change even if the sheet name is changed by user.
Sheet1.Select

If Range("B1") = "" And Range("B7") = "" And Range("B8") = "" Then
inputvar = InputBox("Please Enter the Project Name?")
Range("b1") = inputvar

inputvar2 = InputBox("Please Enter the Start Date")
Range("b7") = inputvar2

inputvar3 = InputBox("Please Enter the Location")
Range("b8") = inputvar3
End If
End Sub


Regards,

OssieMac

"David Andrews" wrote:


Hi guys,

Does anyone know of a way to automatically run a macro on open once
only? i.e. A user opens an excel worksheet, a macro is run prompting
them for some information, they save the file, re-open it however this
time it does not prompt for the questions? Please see below for my
macro. Any help would be greatly appreciated.


Sub Project()

Dim inputvar As String
Dim inputvar2 As String
Dim inputvar3 As String

inputvar = InputBox("Please Enter the Project Name?")
Range("b1") = inputvar

inputvar2 = InputBox("Please Enter the Start Date")
Range("b7") = inputvar2

inputvar3 = InputBox("Please Enter the Location")
Range("b8") = inputvar3

End Sub

*** Sent via Developersdex http://www.developersdex.com ***

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a macro to automatically open excel [email protected] uk Excel Discussion (Misc queries) 1 July 20th 08 09:42 PM
Automatically running an Excel macro on open once only David Andrews[_2_] Excel Programming 2 October 24th 07 04:08 AM
Excel 2003 - Keep a Macro Running While the Workbook is Open MaxRoberts22 Excel Programming 4 January 10th 06 07:33 PM
Running a Macro automatically from Excel Brakeshoe Excel Worksheet Functions 1 July 13th 05 11:23 PM
How to run a macro automatically when i open my excel spreadsheet Harinath Excel Programming 2 April 8th 04 07:31 AM


All times are GMT +1. The time now is 07:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"