Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Save As code

Hi,

I am looking to automate my daily Save As. I create an updated workbook
every day that needs to be saved with a name and Date. The name XYZ is the
same, but it is followed with a Date that is located in Cell B2 of sheet ABC.
Does anyone know if I can create a macro that will save my file with the
name and date located in cell b2? Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Save As code

The following macro verifies that there is a date in B2 in the sheet named
ABC, and if not it uses the current date. The date is formatted as text with
dashes between the month-day-year as the "/" is an invalid character in a
filename:

Sub SaveWithDate()
'
Dim wb As Workbook
Dim ws As Worksheet
Dim varVal As Variant
Dim strFileName As String

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("ABC")
varVal = ws.Range("B2").Value

If IsDate(varVal) Then
strFileName = "DataFile_" & Format(CStr(varVal), "mm-dd-yyyy") &
".xls"
Else
strFileName = "DataFile_" & Format(CStr(Date), "mm-dd-yyyy") & ".xls"
End If

ActiveWorkbook.SaveAs Filename:=strFileName

Set wb = Nothing
Set ws = Nothing

End Sub

--
Kevin Backmann


"Aaron" wrote:

Hi,

I am looking to automate my daily Save As. I create an updated workbook
every day that needs to be saved with a name and Date. The name XYZ is the
same, but it is followed with a Date that is located in Cell B2 of sheet ABC.
Does anyone know if I can create a macro that will save my file with the
name and date located in cell b2? Thank you in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Save As code

Hi again, and thanks so much. That worked great. If possible, could you
please tell me how to add a directory...meaning I would like to save it to a
different folder...directory is something like Departments/Cutting/Old
Schedules

Thank you much



"Kevin B" wrote:

The following macro verifies that there is a date in B2 in the sheet named
ABC, and if not it uses the current date. The date is formatted as text with
dashes between the month-day-year as the "/" is an invalid character in a
filename:

Sub SaveWithDate()
'
Dim wb As Workbook
Dim ws As Worksheet
Dim varVal As Variant
Dim strFileName As String

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("ABC")
varVal = ws.Range("B2").Value

If IsDate(varVal) Then
strFileName = "DataFile_" & Format(CStr(varVal), "mm-dd-yyyy") &
".xls"
Else
strFileName = "DataFile_" & Format(CStr(Date), "mm-dd-yyyy") & ".xls"
End If

ActiveWorkbook.SaveAs Filename:=strFileName

Set wb = Nothing
Set ws = Nothing

End Sub

--
Kevin Backmann


"Aaron" wrote:

Hi,

I am looking to automate my daily Save As. I create an updated workbook
every day that needs to be saved with a name and Date. The name XYZ is the
same, but it is followed with a Date that is located in Cell B2 of sheet ABC.
Does anyone know if I can create a macro that will save my file with the
name and date located in cell b2? Thank you in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Save As code

Oops, I figured it out...just needed to insert the chdir. Thanks much,

Aaron

"Aaron" wrote:

Hi again, and thanks so much. That worked great. If possible, could you
please tell me how to add a directory...meaning I would like to save it to a
different folder...directory is something like Departments/Cutting/Old
Schedules

Thank you much



"Kevin B" wrote:

The following macro verifies that there is a date in B2 in the sheet named
ABC, and if not it uses the current date. The date is formatted as text with
dashes between the month-day-year as the "/" is an invalid character in a
filename:

Sub SaveWithDate()
'
Dim wb As Workbook
Dim ws As Worksheet
Dim varVal As Variant
Dim strFileName As String

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("ABC")
varVal = ws.Range("B2").Value

If IsDate(varVal) Then
strFileName = "DataFile_" & Format(CStr(varVal), "mm-dd-yyyy") &
".xls"
Else
strFileName = "DataFile_" & Format(CStr(Date), "mm-dd-yyyy") & ".xls"
End If

ActiveWorkbook.SaveAs Filename:=strFileName

Set wb = Nothing
Set ws = Nothing

End Sub

--
Kevin Backmann


"Aaron" wrote:

Hi,

I am looking to automate my daily Save As. I create an updated workbook
every day that needs to be saved with a name and Date. The name XYZ is the
same, but it is followed with a Date that is located in Cell B2 of sheet ABC.
Does anyone know if I can create a macro that will save my file with the
name and date located in cell b2? Thank you in advance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Save As code

You can create a string and contcatenate the path to the filename.

Declare a string variable, named strPath in my example and assign the path
string to the variable. Be sure to include the backslash at the end of the
path.

Dim strPath as string

strPath = "C:\Documents\Excel\My Data\"

Then modify the command that saves the file to:

ActiveWorkbook.SaveAs Filename:=strPahtName & strFileName
--
Kevin Backmann


"Aaron" wrote:

Hi again, and thanks so much. That worked great. If possible, could you
please tell me how to add a directory...meaning I would like to save it to a
different folder...directory is something like Departments/Cutting/Old
Schedules

Thank you much



"Kevin B" wrote:

The following macro verifies that there is a date in B2 in the sheet named
ABC, and if not it uses the current date. The date is formatted as text with
dashes between the month-day-year as the "/" is an invalid character in a
filename:

Sub SaveWithDate()
'
Dim wb As Workbook
Dim ws As Worksheet
Dim varVal As Variant
Dim strFileName As String

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("ABC")
varVal = ws.Range("B2").Value

If IsDate(varVal) Then
strFileName = "DataFile_" & Format(CStr(varVal), "mm-dd-yyyy") &
".xls"
Else
strFileName = "DataFile_" & Format(CStr(Date), "mm-dd-yyyy") & ".xls"
End If

ActiveWorkbook.SaveAs Filename:=strPahtName & strFileName

Set wb = Nothing
Set ws = Nothing

End Sub

--
Kevin Backmann


"Aaron" wrote:

Hi,

I am looking to automate my daily Save As. I create an updated workbook
every day that needs to be saved with a name and Date. The name XYZ is the
same, but it is followed with a Date that is located in Cell B2 of sheet ABC.
Does anyone know if I can create a macro that will save my file with the
name and date located in cell b2? Thank you in advance.

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
Before Save code Kelly Excel Worksheet Functions 4 January 30th 08 03:57 PM
Totally Disabling (^ save ) (Save as) and Save Icon – Which code do I use: harpscardiff[_10_] Excel Programming 8 November 10th 05 12:24 PM
Placing a code before Save & Save As Alex Martinez Excel Programming 1 September 27th 05 06:35 AM
Save without VBA code? Joel Excel Programming 1 June 7th 05 05:15 PM
save without code Roman Töngi Excel Programming 7 January 10th 05 07:52 PM


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