ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can a Macro use Different File Names? (https://www.excelbanter.com/excel-programming/370596-can-macro-use-different-file-names.html)

markmidwest

Can a Macro use Different File Names?
 
I am trying to create a macro that goes across 2 spreadsheets, the name of
the first spreadsheet will remane consistent but the second spreadsheet will
have a randomly generated name. I created a macro that runs the functions
that I need but only if the second spreadsheet name doesn't change, once it
changes I get errors.

Is there a way to create a macro like this?

Thank you in advance for your help.

-Mark

Tom Ogilvy

Can a Macro use Different File Names?
 

Assume there are only two visible workbooks (spreadsheets)
Dim bk as Workbook, bk1 as Workbook, bk2 as Workbook
for each bk in Workbooks
if bk.Windows(1).Visible then
if lcase(bk.name) < "constant.xls" then
sName = bk.name
exit sub
end if
end if
Next

set bk2 = workbooks(sname)
set bk1 = workbooks("constant.xls")

Obviously change constant.xls to the name (in lowercase) of the fixed name
workbook

If you meant sheets in the same workbook, then just use worksheet/worksheets
instead of workbook/workbooks

--
Regards,
Tom Ogilvy
"markmidwest" wrote:

I am trying to create a macro that goes across 2 spreadsheets, the name of
the first spreadsheet will remane consistent but the second spreadsheet will
have a randomly generated name. I created a macro that runs the functions
that I need but only if the second spreadsheet name doesn't change, once it
changes I get errors.

Is there a way to create a macro like this?

Thank you in advance for your help.

-Mark



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

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