0 votes
in VBA by Beginner (4 points)

'Select Data in URL / Copy to Clipboard
'Enumerator = 0, _DODEFAULT
'Enumerator = 2, _DONTPROMPTUSER

'// SelectAll
    Application.Wait DateAdd("s", 1, Now)
'// Copy selection
    Application.Wait DateAdd("s", 1, Now)

The code to "Select All" and "Copy" from a webpage has suddenly stopped working

Any suggestions to resolve ?

1 Answer

+1 vote
by Super Expert (3.2k points)

Does it create an error or just not copy anything to the clipboard? I don't know what code is before this but try to make sure you're waiting until the IE application fully loads. You can do this with a code block like this:

Do While objIE.readyState = 4: DoEvents: Loop
Do Until objIE.readyState = 4: DoEvents: Loop
While objIE.Busy


by Beginner (4 points)


As the IE page can take up to 10 seconds to fully load, I use a belt and braces approach.

#1 already use the code you suggest

#2 wait until I can visibly see the IE page has been fully loaded before trying to select / copy

The process works great on one machine, but suddenly stopped working on a different machine

The debug is generated at the line


Inline image

I can still manually Select All ( Ctrl+A ) and Copy ( Ctrl+C ) to the clipboard whilst the IE page is open

... but not automatically using the VBA code


Any ideas why ?



by Skilled (749 points)

Maybe the other machine doesn't have a necessary Reference.
In VBE, see Tools > References....

Instead of objIE.ExecWB... you might try something like 
Application.SendKeys "^a^c", True


by Beginner (4 points)
Thanks for suggestions

... yes, I had already checked that the correct references were checked

... no, not tried the 'sendKeys' method ... understood that it should always be a last resort ... but tried to substitute the objIE.ExecWB code for your sendKeys code without success so far
by Super Expert (3.2k points)
Do the two machines have different versions of IE installed, by chance?
by Beginner (4 points)
Both machines running latest version IE 11
by Super Expert (3.2k points)
This is very strange. I've tested the code on a couple machines here and it seems to work fine. If you navigate to a different website on the machine where it fails, does it properly select all and copy? I'm curious to see if it's something to do with the loading of the particular site you're navigating to.
by Beginner (4 points)

So that we are testing exactly the same code ... would you let me have the code you have used ... and I will test on both machines


by Skilled (749 points)

Before using SendKeys or objIE.ExecWB... to Select All/Copy, make sure IE is the Active Window. See the VBA AppActivate statement.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.