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 Expert (805 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 Expert (805 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
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

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