LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro save as from Template

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
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
Save as Template janey New Users to Excel 2 March 2nd 10 05:13 PM
When you hit Save on a template, how can you save as worksheet? cwgirl1982 Excel Worksheet Functions 1 September 4th 08 11:18 PM
don't save macro results in template Kate[_2_] Excel Programming 2 May 22nd 06 09:08 PM
Save macro in template ? David Excel Programming 3 August 12th 03 12:29 AM
Can I save a macro in a template? David Excel Programming 1 August 6th 03 03:17 AM


All times are GMT +1. The time now is 05:24 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"