Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'd use Data|Validation to try to make sure that only Swing, Power, Grave could
be entered in that cell. See Debra Dalgleish's site for notes about Data|Validation: http://contextures.com/xlDataVal01.html Untested, but it did compile: Option Explicit Public Sub SaveAsDate() Dim fDate As String Dim fShift As String Dim blValid As Boolean Dim fPath As String fPath = "\\pcfile\shared\operations\security\DAR by dates\" blValid = False With ActiveSheet.Range("B4") If Not IsEmpty(.Value) Then If IsDate(.Value) Then blValid = True fDate = Format(.Value, "yyyy-mm-dd") End If End If End With 'what cell contains the shift? With ActiveSheet.Range("b5") Select Case LCase(.Value) Case Is = LCase("Swing"), LCase("Power"), LCase("Grave") fShift = .Value 'ok Case Else blValid = False End Select End With If Not blValid Then MsgBox prompt:="Check Date and Shift fields, file not saved!", _ Buttons:=vbCritical, _ Title:="File NOT saved!" Else With ActiveWorkbook On Error Resume Next .SaveAs fPath & "DAR" & "_" & fShift & "_" & fDate & ".xls" If Err.Number < 0 Then MsgBox Err.Number & vbLf & Err.Description Err.Clear Else MsgBox prompt:="File saved successfully!", _ Buttons:=vbInformation, _ Title:="File was saved!" End If On Error GoTo 0 End With End If End Sub Alon Davis wrote: Thanks Dave for all your help. I have one more request for this macro. I would like to include the contents of one more cell in the name of the document. It is the name of the shift so the final name of the document will be DAR_Shift_<Date.xls I would however like to validate the contents before saving it. Much like the macro verify's it is a valid date before saving the document. The three shifts are Swing, Power, Graves. Thanks again for all you help. -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Save as Template | New Users to Excel | |||
When you hit Save on a template, how can you save as worksheet? | Excel Worksheet Functions | |||
don't save macro results in template | Excel Programming | |||
Save macro in template ? | Excel Programming | |||
Can I save a macro in a template? | Excel Programming |