Save As with a dynamic date parameter

Hi!  I'm trying to create a batch file that opens an Excel file (successfully created in an earlier section of the batch) and Saves As a new dynamic name with the current date so that it doesn't get overwritten the next day.

I can get the file to open and close, but it's not executing the Save As. Any feedback would be greatly appreciated

set ObjExcel = CreateObject("Excel.Application")
set ObjWorkbook = ObjExcel.Workbooks.Open("\\FILELOCATION\FILENAME_.xlsx")
objExcel.Application.Visible = True

objWorkbook.SaveAs "FILELOCATION\FILENAME_" & Format(Date, "yyyymmdd") & ".xlsx"

objWorkbook.Close
objExcel.Quit

set ObjExcel = nothing
set ObjWorkbook = nothing

WScript.Quit
Trinni SchreierAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,
pls try
objWorkbook.SaveAs "FILELOCATION\FILENAME_" & Year(Date) & Right("0" & Month(Date),2)  & Right("0" & Day(Date),2)  & ".xlsx"

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieAnalyst Assistant Commented:
You appear to be missing the \\ at the start of the path, try this.
objWorkbook.SaveAs "\\FILELOCATION\FILENAME_" & Format(Date, "yyyymmdd") & ".xlsx"

Open in new window


Or perhaps this which uses the path from the workbook being opened and appends the date to the filename.
With objWorkbook
    .SaveAs Replace(.FullName, ".xlsx", Format(Date, "yyyymmdd") & ".xlsx"), .FileFormat
End With

Open in new window

0
Rgonzo1971Commented:
AFAIK Format is not a VBS function
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

NorieAnalyst Assistant Commented:
Rgonzo

I think you are right, suppose I'm just use to, incorrectly of course, using VBA functions in VBS.
0
Trinni SchreierAuthor Commented:
Thank you all for your feedback! @Rgonzo's syntax with plus @Norie's 2nd  recommendation works like a charm!
0
Trinni SchreierAuthor Commented:
Thank you again!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.