PC Review


Reply
Thread Tools Rate Thread

Automatically running an Excel macro on open once only

 
 
David Andrews
Guest
Posts: n/a
 
      24th Oct 2007

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 With Quote
 
 
 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      24th Oct 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a macro to automatically open excel another excel file swain.s@blueyonder.co uk Microsoft Excel Misc 1 20th Jul 2008 09:21 PM
Automatically running an Excel macro on open once only David Andrews Microsoft Excel Programming 2 24th Oct 2007 04:08 AM
Running a Macro automatically from Excel =?Utf-8?B?QnJha2VzaG9l?= Microsoft Excel Worksheet Functions 1 13th Jul 2005 11:23 PM
launching excel, opening a file, and running a macro automatically Bernie Yaeger Microsoft Excel Discussion 2 17th Sep 2004 02:41 AM
running macro automatically in Excel longzoo Microsoft Excel Programming 7 18th Mar 2004 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:25 PM.