Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 877
How to use a macro to rename the file on the client

This article relates to a known browser issue. When ExcelWriter streams a file to the client, it sets the appropriate response headers telling the browser the name of the file. However, some browsers do not correctly interpret the response headers and open the file on the client machine with the name of ASP or ASP.NET page or servlet.

One solution is to create a macro in your template spreadsheet which will rename the file correctly when it opens on the client. We will discuss this approach.


The following VBA code will rename the file in the Workbook_Open event, using a value in a particular cell. In this example, the value is placed in cell A1 for simplicity.

Private Sub Workbook_Open()
   ThisWorkbook.SaveAs Filename:=Range("A1").Value
End Sub

If you want to generate the filename at runtime, you can dynamically populate the cell which will referenced by the macro.

For example, if you are using the ExcelTemplate object you can place a data marker such as %%=$filename into a hidden cell in your template spreadsheet. Then, at runtime, dynamically generate the correct filename and bind the string to the datamarker, using the setCellDataSource() method.

Note: Other possible workarounds for the issue of the browser not preserving the filename correctly are:

  1. Save the file temporarily on the server and redirect the client to the actual file.
  2. Use OfficeWriter assistant on the client to open the file with the desired name. For more information about using the OfficeWriter assistant, see the OfficeWriter documentation.

Related Links
OfficeWriter Home Page
OfficeWriter Enterprise Edition
Latest OfficeWriter News
OfficeWriter: Programmatic Runtime Control

Created : 8/6/2004 4:03:01 PM (last modified : 8/6/2004 4:03:01 PM)
Rate this article!