mkasson
Programmer
- Jan 3, 2004
- 36
I'm setting up a small Excel VBA add-in so that as soon as I open or create an Excel file (the "target"
it will change from Excel's standard colors to our company's colors (colors good for color laser and also that can be distinguished when printed on a b/w laser, etc).
I tried starting the color changes in a Workbook_Open macro in the add-in's ThisWorkbook. It does this by calling a macro in Module1 with a series of lines like:
Two problems:
1) When I open an Excel file I get "Run time error 91: Object variable or with block variable not set". There is no With block, so it must must be a variable reference problem - I'm guessing relating to ActiveWorkbook.
Notably, if I select the "Debug" option and then tell it continue having made no change, it continues with no error - though it does not make the changes to the file I am opening.
I am guessing that ActiveWorkbook is referring to the add-in's workbook and not my "target". I am guessing that the add-in macro gets run before the target file is loaded? And perhaps by the time I am debugging, the target file is loaded?
Tried MsgBoxing the number and names of the open Workbooks in the middle of the macro and my add-in is the one open Workbook.
2) And of course, the colors aren't getting loaded, though I think if we clear up 1, 2 will follow.
Any help would be greatly appreciated. Much thanks.
- MSK
I tried starting the color changes in a Workbook_Open macro in the add-in's ThisWorkbook. It does this by calling a macro in Module1 with a series of lines like:
Code:
ActiveWorkbook.Colors(XLCP(i)) = CAx(i)
[XLCP and CAx are module level arrays dimmed as Long.]
Two problems:
1) When I open an Excel file I get "Run time error 91: Object variable or with block variable not set". There is no With block, so it must must be a variable reference problem - I'm guessing relating to ActiveWorkbook.
Notably, if I select the "Debug" option and then tell it continue having made no change, it continues with no error - though it does not make the changes to the file I am opening.
I am guessing that ActiveWorkbook is referring to the add-in's workbook and not my "target". I am guessing that the add-in macro gets run before the target file is loaded? And perhaps by the time I am debugging, the target file is loaded?
Tried MsgBoxing the number and names of the open Workbooks in the middle of the macro and my add-in is the one open Workbook.
2) And of course, the colors aren't getting loaded, though I think if we clear up 1, 2 will follow.
Any help would be greatly appreciated. Much thanks.
- MSK