Update - Include cell contents in filename automatically

  • Thread starter Thread starter Bryan Linton
  • Start date Start date
B

Bryan Linton

Thanks to grinning_crow for this post telling me how to automatically
include contents of a cell in a filename when saving:
As far as I know there are two things you could do;

This would simply save the file automatically and not give them a
chance to change the name, adding the contents of cell A1 to the end of
your specified string:

sub workbook_beforeclose(cancel as integer)

activeworkbook.saveas "Field Rating - " & sheet1.range("A1")

end sub

It's not working yet; I get the following error:

Compile Error: Procedure declaration does not match description
of event or procedure having the same name

Additionally, this Sub uses the BeforeClose method (terminology?) so it only
activates when the user tries to close the workbook; I'd like it to happen
when they try to "Save" or "Save As...." I tried substituting the
BeforeSave method instead but it produced the same error on "Save" or "Save
As..." actions. The section of code highlighted on the error was the
following:

Private Sub Workbook_BeforeSave(Cancel As Integer)

Don't think it's related, but I changed the cell reference to C3 since
that's where the customer name lives and that's what I'd like this sub to
pull into the filename. C3 is a merged cell, if that makes any difference.

Any direction is appreciated...I feel like I'm so close!

Bryan
 
when entering an event, you should select the event from the dropdowns at
the top if the module. then the event will be entered properly rather than
improperly as you show - which causes the error you describe.

You can learn about events at Chip Pearson's site:

http://www.cpearson.com/excel/events.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top