Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default input box upon opening workbook

I want to have an input box that will ask for a date when a workbook is
opened.
I want to be able to us the date that is input in code that will be run
from a macro.

The reason I want the input box upon open instead of when the macro is
run, is because the end user uses the file repeatedly for multiple
calculations. This date will be applied to all of the calculations,
and I don't want the user to have to enter the same date over and over.


I assume that I need something like a "public enddate as date" in the
ThisWorkbook object.


This however doesn't work. What do I need to do to be able to
reference the inputed date later?


TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default input box upon opening workbook

Hi Papa

'top of a normal module
Public pDate As Date

Sub GetDate()
Dim minDate As Date, maxDate As Date
Dim n As Byte
Dim sTtile As String, sPrompt As String, s As String

pDate = 0
minDate = Date - 7 '7 days ago
maxDate = Date + 365 '1 year hence

sTitle = "My Title"
sPrompt = "Enter date between " & minDate & " & " & maxDate

On Error Resume Next
retry:
n = n + 1
v = InputBox(s & sPrompt, sTitle, Date)
pDate = CDate(v)

If pDate = 0 Or pDate < minDate Or dt maxDate Then
If n < 5 Then
s = v & " not valid" & vbCr
GoTo retry
Else
MsgBox "Give up"
End If
Else
Reply = MsgBox(Format(pDate, "yyyy mmm dd"), vbYesNoCancel)
If Reply = vbNo Then
n = 0
GoTo retry
ElseIf Reply = vbCancel Then
pDate = 0
End If

End If


End Sub

Sub test()

If pDate = 0 Then
GetDate
Else: MsgBox "already got date " & pDate
End If
End Sub

'Sub Auto_Open()
'GetDate
'End Sub


You could get your date from Auto_Open or Workbook_Open event, but why not
place this line in any routine that needs the date:

If pDate = 0 Then GetDate

But if you really want to get it on Open uncomment the Auto_Open sub.

Edit or remove the stuff about min/max dates and retrys (if any) and
confirmation.

Regards,
Peter T


"Papa Jonah" wrote in message
...
I want to have an input box that will ask for a date when a workbook is
opened.
I want to be able to us the date that is input in code that will be run
from a macro.

The reason I want the input box upon open instead of when the macro is
run, is because the end user uses the file repeatedly for multiple
calculations. This date will be applied to all of the calculations,
and I don't want the user to have to enter the same date over and over.


I assume that I need something like a "public enddate as date" in the
ThisWorkbook object.


This however doesn't work. What do I need to do to be able to
reference the inputed date later?


TIA



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
How do I stop blank workbook from opening when opening an existing kjg Excel Discussion (Misc queries) 3 February 12th 10 09:36 PM
Opening files with a input box mk389[_3_] Excel Programming 2 November 20th 04 02:42 AM
excel VBA problem - setting workbook as variable & opening/re-opening safe Excel Programming 1 August 20th 04 12:22 AM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
How to make opening of workbook conditional of opening of another workbook turk5555[_2_] Excel Programming 2 December 15th 03 11:07 PM


All times are GMT +1. The time now is 02:16 AM.

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

About Us

"It's about Microsoft Excel"