ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Recorded Macro Works, Code Doesn't (https://www.excelbanter.com/excel-programming/415279-recorded-macro-works-code-doesnt.html)

Jay

Recorded Macro Works, Code Doesn't
 
Hello all,

This is an question that I can't solve, but it's not a terribly important
issue.

I've been tasked to rewrite some macros that various users have recorded.
It's fairly straightforward and I don't have any problems. But there's two
lines of code that are all over the macro, and I can't figure out how they
were recorded. If I copy those two lines and try to run them
independently, it crashes. But the macro works fine by itself. I'm
wondering if I'm missing something, thought I'd throw it out there. Again,
this is just to satify my curiousity.

The lines a
ActiveWindow.Visible = False
ActiveWindow.Activate

These two lines appear maybe 5 times per macro. But the user can't remember
what they did, and I haven't been able to duplictate it.

I can duplicate each line, but not together (in that order). I have to hide
the sheet to get the first line, but activate doesn't work with a hidden
sheet.

Anyone smarter know what's going on?

Thanks,
Jay
--
Disregard, this is so I can find my post later.
***postedbyJay***

J Sedoff comRemove>

Recorded Macro Works, Code Doesn't
 
I don't understand why a user would want to hide the book, but still activate
it... My guess would be taht you could get rid of the first line but keep
the second (the second puts focus on the active window (or the current
Workbook, for us laymen)), which allows the macro to follow up with
appropriate selections of different worksheets and cells on said worksheets.

ActiveWindow.Visible = False
ActiveWindow.Activate


The first line closes my workbook when I tried to recreate it.. I don't know
why a user would want to close a workbook that way (and not just actually
close it..)

Hope this helps, Jim
--
I appreciate any feedback. Please don''t be scared to say that "Yes"
I/someone else did answer your question. Thank you.

desertres

Recorded Macro Works, Code Doesn't
 
Hi,

Those 2 lines of code do work, if you have more than 1 window(file) open.
When the first file is hidden, the next file becomes active. As already said,
this was written in the recording mode, so just ditch that second
line...better to also know if it is really necessary to use a relative
reference in the first line. If a user somehow clicks to another window, then
that gets zapped and the macro starts chaos.


"Jay" wrote:

Hello all,

This is an question that I can't solve, but it's not a terribly important
issue.

I've been tasked to rewrite some macros that various users have recorded.
It's fairly straightforward and I don't have any problems. But there's two
lines of code that are all over the macro, and I can't figure out how they
were recorded. If I copy those two lines and try to run them
independently, it crashes. But the macro works fine by itself. I'm
wondering if I'm missing something, thought I'd throw it out there. Again,
this is just to satify my curiousity.

The lines a
ActiveWindow.Visible = False
ActiveWindow.Activate

These two lines appear maybe 5 times per macro. But the user can't remember
what they did, and I haven't been able to duplictate it.

I can duplicate each line, but not together (in that order). I have to hide
the sheet to get the first line, but activate doesn't work with a hidden
sheet.

Anyone smarter know what's going on?

Thanks,
Jay
--
Disregard, this is so I can find my post later.
***postedbyJay***


Jay

Recorded Macro Works, Code Doesn't
 
That's why I was confused. If I only have one file open (the one containing
the macro) the code still runs. There's no error.

I'm removing all similar lines because it's not required for the macro to
function. Just the behaviour of the code didn't match my expectations. And
I couldn't duplicate it.

Appreciate both your responses.
--
Disregard, this is so I can find my post later.
***postedbyJay***


"desertres" wrote:

Hi,

Those 2 lines of code do work, if you have more than 1 window(file) open.
When the first file is hidden, the next file becomes active. As already said,
this was written in the recording mode, so just ditch that second
line...better to also know if it is really necessary to use a relative
reference in the first line. If a user somehow clicks to another window, then
that gets zapped and the macro starts chaos.


"Jay" wrote:

Hello all,

This is an question that I can't solve, but it's not a terribly important
issue.

I've been tasked to rewrite some macros that various users have recorded.
It's fairly straightforward and I don't have any problems. But there's two
lines of code that are all over the macro, and I can't figure out how they
were recorded. If I copy those two lines and try to run them
independently, it crashes. But the macro works fine by itself. I'm
wondering if I'm missing something, thought I'd throw it out there. Again,
this is just to satify my curiousity.

The lines a
ActiveWindow.Visible = False
ActiveWindow.Activate

These two lines appear maybe 5 times per macro. But the user can't remember
what they did, and I haven't been able to duplictate it.

I can duplicate each line, but not together (in that order). I have to hide
the sheet to get the first line, but activate doesn't work with a hidden
sheet.

Anyone smarter know what's going on?

Thanks,
Jay
--
Disregard, this is so I can find my post later.
***postedbyJay***


Jay

Recorded Macro Works, Code Doesn't
 
Figured it out.

The ActiveWindow.Visible = False code was recorded when there was a dialog
bog (for editing various chart properties) was closed, and
ActiveWindow.Activate was recorded when focus returned to the worksheet.

That's how the macro had those two lines.
--
Disregard, this is so I can find my post later.
***postedbyJay***


"Jay" wrote:

Hello all,

This is an question that I can't solve, but it's not a terribly important
issue.

I've been tasked to rewrite some macros that various users have recorded.
It's fairly straightforward and I don't have any problems. But there's two
lines of code that are all over the macro, and I can't figure out how they
were recorded. If I copy those two lines and try to run them
independently, it crashes. But the macro works fine by itself. I'm
wondering if I'm missing something, thought I'd throw it out there. Again,
this is just to satify my curiousity.

The lines a
ActiveWindow.Visible = False
ActiveWindow.Activate

These two lines appear maybe 5 times per macro. But the user can't remember
what they did, and I haven't been able to duplictate it.

I can duplicate each line, but not together (in that order). I have to hide
the sheet to get the first line, but activate doesn't work with a hidden
sheet.

Anyone smarter know what's going on?

Thanks,
Jay
--
Disregard, this is so I can find my post later.
***postedbyJay***



All times are GMT +1. The time now is 12:44 AM.

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