ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   launching macro on workbook loading (https://www.excelbanter.com/excel-programming/280438-launching-macro-workbook-loading.html)

Ric[_2_]

launching macro on workbook loading
 
Hi,

Is there a way to have a macro automatically run every time an excel
workbook is opened, where the macro in question resides in the personal.xls
or an add-in rather than being part of the document that is being loaded?

Thanks,
Ric



Tom Ogilvy

launching macro on workbook loading
 
If you want to instantiate application level events and have the open event
check each workbook opened to see it is the one - then run the code.

see Chip Pearson's site on application level events

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

--
Regards,
Tom Ogilvy

"Ric" wrote in message
...
Hi,

Is there a way to have a macro automatically run every time an excel
workbook is opened, where the macro in question resides in the

personal.xls
or an add-in rather than being part of the document that is being loaded?

Thanks,
Ric





Ric[_2_]

launching macro on workbook loading
 
Tom Ogilvy wrote:
If you want to instantiate application level events and have the open
event check each workbook opened to see it is the one - then run the
code.

see Chip Pearson's site on application level events

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


"Ric" wrote in message
...
Hi,

Is there a way to have a macro automatically run every time an excel
workbook is opened, where the macro in question resides in the
personal.xls or an add-in rather than being part of the document
that is being loaded?

Thanks,
Ric


Thanks. This works.

I have one annoying problem, though. I now have a macro that runs whenever a
workbook is opened that does a search and replace of a text string on each
sheet of the workbook. However, now I'm always asked if I want to save
changes when I close a workbook, even if the string searched for did not
exist in that workbook. Is there any way to do a search and replace but
leave the "changed" status of the workbook as unchanged if the text string
was not found?

Thanks,
Ric



Tom Ogilvy

launching macro on workbook loading
 
workbooks("MyWorkbook.xls").Saved = True

will mark the workbook as unchanged.

so if your macro makes not changes, have it set this property to true after
it has done its search and found no match.

--
Regards,
Tom Ogilvy

Ric wrote in message
...
Tom Ogilvy wrote:
If you want to instantiate application level events and have the open
event check each workbook opened to see it is the one - then run the
code.

see Chip Pearson's site on application level events

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


"Ric" wrote in message
...
Hi,

Is there a way to have a macro automatically run every time an excel
workbook is opened, where the macro in question resides in the
personal.xls or an add-in rather than being part of the document
that is being loaded?

Thanks,
Ric


Thanks. This works.

I have one annoying problem, though. I now have a macro that runs whenever

a
workbook is opened that does a search and replace of a text string on each
sheet of the workbook. However, now I'm always asked if I want to save
changes when I close a workbook, even if the string searched for did not
exist in that workbook. Is there any way to do a search and replace but
leave the "changed" status of the workbook as unchanged if the text string
was not found?

Thanks,
Ric





Ric[_2_]

launching macro on workbook loading
 
Helpful as usual. Thanks!

Ric

Tom Ogilvy wrote:
workbooks("MyWorkbook.xls").Saved = True

will mark the workbook as unchanged.

so if your macro makes not changes, have it set this property to true
after it has done its search and found no match.


Ric wrote in message
...
Tom Ogilvy wrote:
If you want to instantiate application level events and have the
open event check each workbook opened to see it is the one - then
run the code.

see Chip Pearson's site on application level events

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


"Ric" wrote in message
...
Hi,

Is there a way to have a macro automatically run every time an
excel workbook is opened, where the macro in question resides in
the personal.xls or an add-in rather than being part of the
document that is being loaded?

Thanks,
Ric


Thanks. This works.

I have one annoying problem, though. I now have a macro that runs
whenever a workbook is opened that does a search and replace of a
text string on each sheet of the workbook. However, now I'm always
asked if I want to save changes when I close a workbook, even if the
string searched for did not exist in that workbook. Is there any way
to do a search and replace but leave the "changed" status of the
workbook as unchanged if the text string was not found?

Thanks,
Ric






All times are GMT +1. The time now is 03:20 PM.

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