I added "Dim t As Long" into the sub "Pause". The error was then resolved.
Excellent - well done. This means that you have "Option Explicit" at the top of your code module. I wasn't aware of that, but it is of course best practice to include that in every code module and to properly dimension any variables used in subroutines, functions. My apologies.
I realized that the splash screen no longer appeared, and guessed that removing this portion might work and to my surprise, it did work. With that, i figured that "pause" was the answer, which leads to my first question.
That is exactly right. If I had more time, a better approach would be first to test whether the popup was present before telling Excel to click on an HTML element that simply didn't exist, thus causing the error. In my testing, though, I noted that the splash screen came up everytime I ran the routine, so I didn't think to test whether or not it was coming up at all - the only difference I noticed each time I ran it, though, was in how long it took for the splash screen to appear, which is why I added a "Pause" sub.
What is the best time to pause? If the answer on the best time to pause depends on variables, how should i determine it (trial and error and see time works best[shorter is better?])?
No idea. I just guessed it at around 5 seconds for the splash screen (after some trial-and-error), thinking perhaps that speed was not a primarily concern for you.
2) With regards to my 2nd question, assuming my assumption that the splash screen appears for "x" number of times per day is correct and is causing problems?
Should I or can I write a code (e.g if "shopee-popup__close-btn" gives an error, on error resume next). Is this better?
On Error Resume Next
would be the easy way of bypassing the problem, but you should remember to reset the error handling process with
On Error Goto 0
immediately after that. The Resume Next approach may seem like it will solve any and all problems, but it can sometimes cause more problems than it solves. On that, I'd recommend learning about Error Handling. Excel Macro Mastery has a
very good guide.
I think the better approach would be: (1) first test whether or not an HTML element with that class name exists in the code; and then (2a) if it does, click on it; or (2b) if it doesn't, just keep doing what you're doing.
That would certainly improve the speed of your automation code rather than 'pausing' for an arbitrary number of seconds (which is my lazy approach to things...).