Link to home
Start Free TrialLog in
Avatar of garyrobbins
garyrobbinsFlag for United States of America

asked on

I need the current date added to the excel doc name when i export from Access

I have a macro that auto export and saves as excel but I want to add the current date to the file name.  

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro MinimumClientDesignVersion="14.0.0000.0000"><Statements><Action Name="ExportWithFormatting"><Argument Name="ObjectType">Query</Argument><Argument Name="ObjectName">Daily AR Trending</Argument><Argument Name="OutputFormat">ExcelWorkbook(*.xlsx)</Argument><Argument Name="OutputFile">A:\1. Robbins, John\Daily Reports\Daily AR Trending\Daily Info</Argument></Action></Statements></UserInterfaceMacro></UserInterfaceMacros>
SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of garyrobbins

ASKER

A:\1. Robbins, John\Daily Reports\Daily AR Trending\fnFileNameAndDate = BaseName & Format(Date(), "yyyy-mm-dd")


Like this?
Yes, though you might want to put a space or dash before the date.  You can use various formats, so long as they don't include slashes, which are not allowed in file names.
It is not working.  This what i am trying to save the file as.

A:\1. Robbins, John\Daily Reports\Daily AR Trending\ fnFileNameAndDate = Daily AR Info & Format (Date(), "yyyy-mm-dd")
Gary,

I just tested the technique I recommended above, calling a function as the Output File, although I did have to change my function to add the file extension as follows:

Public Function fnFilename(BaseName As String) As String

    fnFilename = BaseName & "_" & Format(Date, "yyyy-mm-dd") & ".xlsx"

End Function

Here is what my macro settings look like:User generated imageThis generated an Excel file with the name I passed as the BaseName to the function.
Dale,

Where are you entering the below information?

Public Function fnFilename(BaseName As String) As String

    fnFilename = BaseName & "_" & Format(Date, "yyyy-mm-dd") & ".xlsx"

End Function

Sorry about the multiple threads,
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dale

You ROCK, Working GREAT!   I learn so many things that I will be able to apply else where.

Can I create multiple Public Functions on the same module?
Glad to help.

Yes, you can put multiple functions or subroutines in a single code module, but I like to keep the modules somewhat focused on a particular subject.  If you look at the  image above, you will see modules for date functions, text functions, menus, commandbars, ...

That organization makes it easier to find what you are looking for.