Gentlemen (Roger Govier, Bob Phillips, Michael Bednarek, Ken Macksey),
This project got so urgent they brought in another VBA programmer (the
third!) to try to work out why this program used to work and now
doesn't. The mystery has been solved. By the way, I always try to give
feedback to those kind souls who try to help me out with my programming
problems. I know you don't always get feedback, but you have to
understand that often there is an emergency in progress, someone posts
the problem, a kind soul solves that problem, and the next few days are
spent frantically implementing the solution and putting out fires.
However, I usually have the time at some point to get back and thank
those who have tried to come to my rescue.
The VBA programmer they brought in (Georgina) found what the problem
was. I have learnt something from all this (well I suppose you would,
wouldn't you, after three people spent three days trying to find out
why a working program wasn't working). But firstly:
1. Roger, Worksheets("ABNLookup").Activate was correct (not "Sheet1").
2. Roger, I have in the last three days become aware of the technique
of not using Selection and Activation and plan on implementing your
recommendations. However, I am neither a good nor confident VBA
programmer yet. Breaking down a programme into its elemental steps
allows me to more easily debug it. In this case here, when I finally
realised that the problem was not being able to activate another
workbook from my programme, it allowed the new programmer to have the
insight into what lay at the core of the problem.
3. Bob, thank you for the recommendation regarding a better way of
implementing my programming intentions. Please see point two above.
4. Michael, wow. I don't have the time at the moment to try to get my
head around your recommendation, but, yeah, I'm getting a little tired
of amateurishly selecting "E2:E65000" as my source range.
5. Ken, yes I have done what you suspected in the past but not in this
case. The worksheet name was correct.
OK. So, what really did Georgina work out to be the problem? Why did
the program work in the past and why isn't it working now? Well, in
developing the programme I had modules everywhere, code everywhere, and
so I recently decided on a little housekeeping. I put all the code into
"ThisWorkbook". And I didn't test to see if it still worked! Guess
what. You can't activate other workbooks if your code is in
"ThisWorkbook". I have never read this anywhere. No one has ever told
me this. Georgina didn't know this. It came to her in a "Eureka"
moment. I have moved the code into a module and it works.
Thank you for all your help. You have given me ideas which will keep me
busy for a while. Incidentally, and this is pure idle curiosity, when
opening the spreadsheet with all of the VBA associated with this
application (of which, I suppose, there is quite a bit), why does it
take almost exactly two minutes to get to the "Enable macros" screen
and a further two and a half minutes after that to open?
Anyway, I wish you all the best and again, thank you.
Regards,
Cloudfall.