ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Saving a file with VBA that references current file name (https://www.excelbanter.com/excel-programming/279905-saving-file-vba-references-current-file-name.html)

Chilidog1000

Saving a file with VBA that references current file name
 
I have a file that has code in it that references the file
name. Problem is when an end user gets the file they save
it as another name and subsequently get a run-time error.
Is there a way to change the VB references in the code to
point to the new file name? Muchos Gracis if you can help,
heck just thanks for reading!

Chip Pearson

Saving a file with VBA that references current file name
 
You can always refer to the workbook containing the code with ThisWorkbook.
From that, you can get the name of the file, if needed, with

ThisWorkbook.Name
' or
ThisWorkbook.FullName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"chilidog1000" wrote in message
...
I have a file that has code in it that references the file
name. Problem is when an end user gets the file they save
it as another name and subsequently get a run-time error.
Is there a way to change the VB references in the code to
point to the new file name? Muchos Gracis if you can help,
heck just thanks for reading!




Rollin_Again

Saving a file with VBA that references current file name
 
If you just want to change the VB reference to the file just open the VB
editor and use the SEARCH and REPLACE feature to locate each instance
of the old filename in the code and then replace it with the new file
name.

Rollin



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com