View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default inserting the name of the current workbook into a cell

On Wed, 23 Jul 2003 17:07:38 -0700, "Paul James"
wrote:

If I wanted to use VBA to insert the name of the current workbook into
sheets(1).range("a1"), is there a way to do this?

Thanks in advance.


You could do something like this:

Private Sub Workbook_Open()
Worksheets(1).Range("A1").Value = ThisWorkbook.Name
End Sub

This is an event macro and will do the insertion when you open the workbook.
To enter it, <alt<F11 opens the VB Editor. Double click on ThisWorkbook on
the pertinent VBA project, and paste the code into the window that opens.

Note that the file has to be saved in order for the Workbook to have an
accessible name. This will be true whether you use this VBA method (which you
requested) or use a formula string manipulation of the CELL worksheet function.


--ron