AppActivate After opening Web Brower

gmooney

Active Member
Joined
Oct 21, 2004
Messages
254
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the following code that essentially looks for a downloaded file before launching the URL and automatically downloading a file.

I want the Excel file to return to focus but this code is not and it is staying on the web browser, thus I have to click on Excel from the taskbar. Any ideas how to get Excel back to be displayed?

VBA Code:
Sub GetURL()

    Dim NewURL As String
    Dim FollowURL As String

    NewURL = ThisWorkbook.Sheets("Category Review").Range("AP107").Value
    
    CheckforDuplicateDownloadFile
    
    ThisWorkbook.FollowHyperlink NewURL
    
    'Sheets("Instructions").Select
    
    AppActivate "Category Review Builder"
    
    WaitForFileDownload
    
    
    
    BuildMyCategoryReview
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I do have to dip for now to get some zzzz's but I will check back in a few to see where this stands.
 
Upvote 0
I do have to dip for now to get some zzzz's but I will check back in a few to see where this stands,
Thanks. Me too. I looked at post 42 and it didn’t appear to be the right post. Thanks @johnnyL for all the help.
 
Upvote 0
You can introduce a small pause as follows : (I have set the delay here to (1) second. You may need to slightly fine tune this delay depending on the how fast the browser is launched)
VBA Code:
Sub GetURL()

    Dim NewURL As String
    Dim FollowURL As String

    NewURL = ThisWorkbook.Sheets("Category Review").Range("AP107").Value

    CheckforDuplicateDownloadFile

    ThisWorkbook.FollowHyperlink NewURL

    Dim t As Single
    t = Timer
    Do: DoEvents: Loop Until Timer - t >= 1 '<===  wait 1 second (change delay as required.)

    Call BringWindowToFront(Application.hwnd)

    WaitForFileDownload

    BuildMyCategoryReview

End Sub
 
Upvote 0
Solution
Ok, that may be what @Dan_W was eluding to, I can't test the 64bit version. :(
That was indeed what I was alluding to. I would have posted the revised lines of code / conditional compilation, but it was already well past my bedtime, and I didn't expect that there would be so much activity in the intervening hours! Sorry! Hopefully it's all sorted now.
 
Upvote 0
You can introduce a small pause as follows : (I have set the delay here to (1) second. You may need to slightly fine tune this delay depending on the how fast the browser is launched)
VBA Code:
Sub GetURL()

    Dim NewURL As String
    Dim FollowURL As String

    NewURL = ThisWorkbook.Sheets("Category Review").Range("AP107").Value

    CheckforDuplicateDownloadFile

    ThisWorkbook.FollowHyperlink NewURL

    Dim t As Single
    t = Timer
    Do: DoEvents: Loop Until Timer - t >= 1 '<===  wait 1 second (change delay as required.)

    Call BringWindowToFront(Application.hwnd)

    WaitForFileDownload

    BuildMyCategoryReview

End Sub
Thank @Jaafar Tribak after changing the timer from 1 to 10 it worked. Once the URL is launched a user has to login thus 1 second was too soon. Appreciate all your help!
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top