Pdeters
asked on
Save Excel Template with a different anme
I am using this code to take a query and save to a Excel template. What I would like is it not to save to the actual template but to a new excel file with a different name so the template stays intact.
DoCmd.TransferSpreadsheet TransferType:=acExport, SpreadsheetType:=acSpreads heetTypeEx cel9, TableName:="qry_SectionOne ", FileName:="C:\Test\Templat e.xlsm", Range:="SectionOne"
DoCmd.TransferSpreadsheet TransferType:=acExport, SpreadsheetType:=acSpreads
HI,
pls try
pls try
DoCmd.TransferSpreadsheet TransferType:=acExport, SpreadsheetType:=acSpreadsheetTypeExcel9, TableName:="qry_SectionOne", FileName:="C:\Test\NewFile.xlsm"
Regards
ASKER
I want to take the Excel Template as it has format etc. and then save it to a new name. The template will be reused and needs to stay blank.
ASKER
I want it the export to use the format that is in the Excel template (has formating etc.) and then save it as a different file name
try to put this code, in the template workbook.
the code should be placed in THisWorkbook
the code should be placed in THisWorkbook
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.SaveAs ThisWorkbook.Path & Application.PathSeparator & Format(Date, "yyyymmdd"), ThisWorkbook.FileFormat
ThisWorkbook.Saved = True
DoEvents
Application.EnableEvents = True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes I am doing this from Access. Is there not a way to take the template and rename from Access?
Yes, you can open template from Access, open your query and loop across lines of query writing them to Excel template. Save it with new name when finished. Main idea is in sample code from crystal's comment.
I've added MS Access to topics
I've added MS Access to topics
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you like to get code, save results of your query to table (only few lines will be enough) and upload DB with this table only (remove any sensitive data). Upload template file also,
If you are using a proper Excel Template, i.e saved as *.xltx or *xltm then it will automatically open as a new workbook. Any changes will not affect the template.
I believe that if you leave the Filename element of the statement out of the code, you will be prompted for a filename and folder location. So delete
FileName:="C:\Test\Templat e.xlsm", from you code.
FileName:="C:\Test\Templat
You should actually be opening the template, which will open as Template1.xlsm, this name can be saved. This process will not affect the original 8.xltm
Copy the spreadsheet to the new name. THEN export to the new name.
Author did not pointed Access as a platform, so many comments were made for excel solutions
Open in new window
And for newer versions of Office you can use:
Open in new window
»bp