+ Reply to Thread
Results 1 to 39 of 39

Need Help! Macro to click hyperlink, save and replace

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Need Help! Macro to click hyperlink, save and replace

    Hello All,

    Really need some help as i'm a bit hopeless with VBA - I've done some recording for small parts but am struggling to create a macro for the following daily process:

    The Process:

    1. I have list of hyperlinks to company reports in column A of an excel workbook and the names each report needs to be 'saved as' in column B
    2. I click on the first hyperlink in the list which triggers an Internet Explorer page to open
    3. The IE page loads and the the 'downloads' window opens asking if I would like to save or open the report
    4. I choose open and the report opens in excel format
    5. I then 'Save As' the report as the name next to the hyperlink in step 1 to a specific folder
    6. I replace yesterday's file with the new one
    7. I then click the next hyperlink in the list and repeat the process

    What i'd like the Macro to do:

    I need the macro to replicate all the clicks and selections as above but in Step 3, it needs to wait until the 'downloads' window appears before continuing and repeat for each hyperlink in the list until the end of the list is reached.



    If anyone can PLEASE help, I would be eternally grateful - this would make my job so much easier!!

    Best Wishes
    Mike

  2. #2
    Registered User
    Join Date
    03-01-2017
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2007
    Posts
    77

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi MRedfern,

    It would be very helpful if you could please attached the sample excel file that you are working with. Just do not forget to remove sensitive data from it.

    Thanks,
    Arnel

  3. #3
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Arnel,

    Thanks for the reply.

    I can't see that helping to be honest as it is just as described - simply a list of URLs and a list of file names.

    I would have to change the URLs anyway as they are company reports so they would be dummy ones anyway.

    The format of the link doesn't end in a document type i.e .doc as the link is to make the report run then open.

    I hope this helps you help me lol!

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    @ MRedfern
    It is easier for someone trying to help you to look at exactly what you are looking at
    A description of the problem is easily misinterpreted
    If your (company) website is not accessible to others, find another one that allows you to replicate your issue
    Create your workbook using those links etc

    You can attach a file by clicking on GoAdvanced and looking below for ManageAttachments

    thanks
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    I will try to replicate and will post later this afternoon.

    Thanks

  6. #6
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    I've created the attached file - Includes 2 example URLs and a screenshot of what I usually see when the report has finished downloading in Internet Explorer.

    Hoping you can help!
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by MRedfern; 10-12-2017 at 04:29 AM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Thanks for the file - I will look at it later this morning and post suggested solution after that.

    I would rather provide you with code that I can personally test as a complete package

    I do not have Internet Explorer on my PC. Do you have Firefox?
    (Code easily modified to use IE later)

  8. #8
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Quote Originally Posted by kev_ View Post
    Thanks for the file - I will look at it later this morning and post suggested solution after that.

    I would rather provide you with code that I can personally test as a complete package

    I do not have Internet Explorer on my PC. Do you have Firefox?
    (Code easily modified to use IE later)
    Many Thanks for your help! I don't have firefox no, but if it can be easily changed to IE in the code, i'm very happy.

    Cheers!

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    The code below does everything you requested and has been tested on my system
    - this works perfectly for me using Firefox (I do not have IE on my PC)
    - I expect it to work for you with very little modification
    - I hope that Internet Explorer does not throw in any tricky surprises
    - VBA subdivided into separate procedures to make it easier to debug each bit in isolation

    THIS TEST
    - this first test uses files we both can access (= those on this forum)
    - the attached workbook contains direct links to 3 files (and the names of the 3 files)
    - the files are downloaded (to default downloads folder) and then moved to selected destination folder
    - before that happens the previous copy of each file is deleted to avoid any confusion
    - files in both folders are deleted
    - this method avoids opening and closing each file which should be unnecessary

    FOR INFO
    - automatically downloading files from the internet is not as straightforward as it may appear when you do things manually
    - a link may not exist (how does VBA handle that?)
    - internet performance is variable
    - controlling the browser via VBA is not simple
    - getting a "handle" on the open tab etc is complicated
    - the code below uses SENDKEYS (something I try to avoid)
    - SENDKEYS are what you would type if doing it manually
    - SENDKEYS can be unpredictable (eg if another program takes the focus) because they apply to the ACTIVE window
    - VBA is fast, but handling things via the internet is slow
    - VBA can easily get ahead of itself
    - so "delays" have been deliberately incorporated to make VBA wait 5 seconds every time
    - be aware that if everything does not download that simply increasing the delay may fix the problem
    - message returned at end if any expected files have not been downloaded

    TO RUN THE TEST
    - open IE and make sure that you are automatically signed into the forum when a new tab is opened (otherwise you cannot download files)
    - browserPath - is this path to Internet Explorer correct?
    - finalPath - create new destination folder on your system and amend finalPath string to match
    - downloadPath - amend string to match your own default download path
    - I woud move existing files out of the downloads folder (you do not have to but it is easier to find test files if they are the only ones!)
    - VBA runs in attached workbook with {CTRL} k
    - when the open/save screen pops up IGNORE IT - VBA should do what's required
    - everything should be complete in less than 30 seconds
    - 3 empty browser tabs need closing manualy at the end (may be able to automate that in IE later)
    - close those and check destination folder

    EXPECTED RESULT
    - new destination folder contains 3 workbooks
    - download folder contains none of them

    FEEDBACK
    - let me know how it goes
    - if VBA throws an error I need to know on which line, the error code and the message
    - is it carrying out the required tasks?
    - is there anything different with the real file? (- even minor differences may require a code mod, so let me know)

    APPLYING TO YOUR SPECIFIC REQUIREMENTS
    - we must ensure everything working correctly using forum files before modifying code to meet to your specific requirement
    - amend finalPath
    - replace links and file names in sheet "Links"


    Const browserPath As String = "C:\Program Files\Internet Explorer\iExplore.exe"     'AMEND (= your Internet Explorer path)
    'Const browserPath As String = "C:\Program Files\Mozilla Firefox\firefox.exe"
    Const finalPath As String = "C:\TestArea\Doc"                                       'AMEND (= destination folder)
    Const downloadPath = "C:\Users\kev\Downloads"                                       'AMEND (= file download folder)
    Const myLinks As String = "Links"
    Dim FSO As Object
    Dim oldFile As String
    Dim ws As Worksheet, filelist As Range, linkList As Range, f As Range, url As Range
    
    Sub Master()
        SetCommonThings
        DeleteOldFiles
        GetLatestFiles
        MoveFiles
    End Sub
    Private Sub SetCommonThings()
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set ws = Sheets(myLinks)
    End Sub
    
    Private Sub DeleteOldFiles()
        Set ws = Sheets(myLinks):    Set filelist = ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp)).Offset(, 1)
        
        For Each f In filelist
            oldFile = finalPath & "\" & f:          If fileExists(finalPath, f) Then Kill oldFile
            oldFile = downloadPath & "\" & f:       If fileExists(downloadPath, f) Then Kill oldFile
        Next f
    End Sub
    
    Private Sub GetLatestFiles()                '
        Set ws = Sheets(myLinks):       Set linkList = ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp))
        
        For Each url In linkList
            Application.DisplayAlerts = False:  'On Error Resume Next
            Shell (browserPath & " " & url.Value)
            Application.Wait (Now() + TimeValue("00:00:05"))
            If Not Err > 0 Then SendKeys "%s~":
            Application.DisplayAlerts = True:   'On Error GoTo 0
        Next url
        Application.Wait (Now() + TimeValue("00:00:05"))
        Application.Windows(ThisWorkbook.Name).Activate
    End Sub
    
    Private Sub MoveFiles()         'moves files from download folder tospecified folder
        Static NotFound As String
        Set ws = Sheets(myLinks):    Set filelist = ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp)).Offset(, 1)
        
        For Each f In filelist
            oldFile = downloadPath & "\" & f
            If fileExists(downloadPath, f) Then
                FSO.movefile Source:=oldFile, Destination:=finalPath & "\"
            Else
                NotFound = NotFound & vbCr & f          'create message string
            End If
        Next f
        If NotFound <> "" Then MsgBox NotFound, vbExclamation, "Files not Found:"
    End Sub
    Function fileExists(aFolderPath, aFileName) As Boolean
        fileExists = FSO.fileExists(aFolderPath & "\" & aFileName)
    End Function
    Attached Files Attached Files
    Last edited by kev_; 10-14-2017 at 11:50 AM.

  10. #10
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    WOWEEE! Thank you SO much for your hard work!! Will read in more detail tomorrow and will complete the testing.

    Will let you know how I get on!

    HUGE Thank you!

    Mike

  11. #11
    Registered User
    Join Date
    10-22-2014
    Location
    d
    MS-Off Ver
    10
    Posts
    1

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    I've completed testing as per your instructions. I've added a couple of screenshots below. The macro is ending without error but the download files are not found - looks like an extra part of the URL is being included in the file name (see Downloads screen shot).

    I'll see if I can resolve but any tips appreciate as usual!

    Many Thanks!
    MikeResult.jpgDownloads.jpg

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    That is an Internet explorer quirk Internet Explorer has added the name of the thread in front of the file name
    Firefox does not do that - the files are downloaded as per the original file name

    FileList.jpg

    I am hoping that when you try this at work, when there is no thread, that this will not occur

    In a few minutes I will send you a mod to make it work for the forum download
    - I think we can use the backend of the file name and that should allow the VBA to move the files.......
    Last edited by kev_; 10-15-2017 at 10:05 AM.

  13. #13
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Many thanks! Really appreciate it :-) I couldn't work out a fix myself.

  14. #14
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Procedure added to rename downloaded files before they are moved
    - VBA should now leave you with 3 files in your destination folder

    Instructions
    1 Delete the 3 files you downloaded earlier
    2 Download the attached workbook
    3 In VBA
    - amend downloadPath
    - amend finalPath
    (and IE path if incorrect)
    4 Run with {CTRL}k

    Let me know how it goes...

    thanks
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    Thanks so much - the test worked!!

    I will now try using my actual URLs - will let you know how I get on!

    Thanks again!!
    Mike

  16. #16
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    OK, just completed a test with a couple of the actual URLs.

    Each report triggered to run from our company's server is different in size which means the time varies until the Downloads window appears. The time taken could be a few seconds up to 45 seconds for the largest.

    I therefore tried changing the first 'TimeValue' in GetLatestFiles() to 45 seconds. Do you know a way to cope with varying report running times?

    Also, a random file name seems to be applied to files when downloaded from the server so they will not be the same. This means the macro is downloading to the downloads folder but are then 'not found' (see screenshot).

    TestActual.jpg

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Excellent
    Try actual links with the original code
    - bloated file names seems to be "Forum/Internet Explorer combo" issue
    - I would be surprised if anything similar happened when downloading from your work intranet

    If it all goes smoothly, I should be able to simplify the look of the code for you - I built it so that it was easy to test sections if anything failed.
    When finalised I will provide you with some explanatory notes.
    Last edited by kev_; 10-15-2017 at 12:07 PM.

  18. #18
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    At least the download is automated.
    I need to have a rethink - my approach was based on "I replace yesterday's file with the new one"
    Can we make the destination folder only contain these files? VBA an delete everything in one hit...

  19. #19
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Quote Originally Posted by kev_ View Post
    Can we make the destination folder only contain these files? VBA an delete everything in one hit...
    Sure, whatever you think would work. Many Thanks!

  20. #20
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    I will update the thread later this morning with revised VBA

  21. #21
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Many Thanks Kev! Really appreciate it

  22. #22
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Here you go
    - amend values in column B of sheet "Links" (see ***below)
    - I suggest you test it with the Forum files first and a dummy destination folder etc
    - then test with your real files


    NOTE that ALL Excel files in destination path are deleted at the outset

    Feature to tailor delays to individual files added
    - amend column B in sheet "Links" ***
    - 3 links in attached file delayed by 3, 5 and 3 seconds respectively
    - default lowest value = 3 seconds (which is in the VBA if you want to change that)

    Check of file count added at the end
    - message box should always confirm that the numbers match
    - otherwise one of the links may be broken or the delay is inadequate (investigation required)

    The VBA is sub-divided into the following procedures:
    SetCommonThings
    DeleteOldFiles - deletes ALL Excel files in finalPath (= yesterday's files)
    ListExcelFiles - establishes what's in downloadPath at start
    GetLatestFiles - download files based on list of links
    ListExcelFiles - establishes what's in downloadPath at after download (added to previous list)
    DownloadedToday - list of what's changed (=anything appearing only once on list)
    MoveFiles - move today's files to destination folder
    CheckFileCount


    Hopefully this does everything you want
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    That's amazing - thank you so much! Will download and have a look when I get home from work

  24. #24
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    I just found a little time so have tested it before I leave - really appreciate you looking at this again!

    I have a couple of questions:

    I've edited the downloads & destination as before. When I ctrl+k, the VBA runs but only opens an IE page and goes no further (but without error or message)

    Also, the option to add delay value is fantastic! But how does the VBA know what to call each file when saving to the destination folder now that the name values aren't in column B?

    Many thanks!

  25. #25
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Update!

    I closed IE completely and ran the VBA and it worked!!

    All I need is the rename function adding back in if you wouldn't mind - but I will try it with the actual URLs now....

  26. #26
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    ah just spotted post#25 - good!!

  27. #27
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Gonna hold off trying with the actual URLs as I think the "save as" filename part will need a fix first.

    This is great stuff! Thanks again

  28. #28
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Apologies for removing an earlier feature
    - I will re-introduce "file renaming" for you
    - have a look at the thread tomorrow morning

  29. #29
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Quote Originally Posted by kev_ View Post
    Apologies for removing an earlier feature
    - I will re-introduce "file renaming" for you
    - have a look at the thread tomorrow morning
    That's fantastic - thank you so much Kev!

  30. #30
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    But how does the VBA know what to call each file when saving to the destination folder now that the name values aren't in column B?
    - I have re-read post#1
    - I seem to have forgotten all about point no5
    - I was thrown distracted by the fact that the file names changes every time
    - that is easy to fix with an extra column

    Ignore this - our posts crossed
    the VBA runs but only opens an IE page and goes no further (but without error or message)
    I have not changed anything to do with the download itself
    - it worked yesterday and should work today
    - the link is whatever is in column A
    - the linked file is simpy downloaded
    Are you saying that the files are not downloading? That does not make sense to me
    Last edited by kev_; 10-16-2017 at 11:49 AM.

  31. #31
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    Let's try again....
    - desired File Names go in column B
    - file specific download delays go in column C (column D is used by VBA)

    Test
    - as per usual test first with forum files
    - amend download and destination paths
    - VBA in attached workbook runs with {CTRL}k

    Summary
    - file links in column B are downloaded
    - as each file is downloaded, VBA identifies latest addition to DownloadPath and adds its name to the worksheet in column D
    - when all files have been downloaded, each file ilisted in column D is moved and renamed
    - internet links are prone to failure (sometimes for no good reason)
    - if any errors are spotted then none of the files are moved (try re-running the VBA first)

    Changes from previous
    - to avoid repeatedly adding "\" in the code, each path (except Internet Explorer) now requires declaring with a trailing "\"
    - message box lists Excel files contained in destination folder at end
    - default delay variables introduced for "navigation" (1 second works for me) and "download"(see note below)
    - separate variable for individual delay value which now needs entering in column C (minimum = 0, max = 59)
    - set DelayDownloadDefault to the time taken to download the quickest file
    - function created to handle the delays
    - column D (cleared at beginning of VBA) contains list of actual downloaded file names
    - column B contains the names that you want for each file
    - NOTE column B should not include the extension
    (if this causes you a problem, it's easily changed - minor VBA mod required)
    Attached Files Attached Files
    Last edited by kev_; 10-17-2017 at 03:47 PM.

  32. #32
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Thank you so much!! You're a superstar. Will test tomorrow at work and will let you know how I get on!

    Really appreciate it

  33. #33
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    Really sorry - today has been crazy but I will make some time at work tomorrow.

    Thanks again

  34. #34
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    Managed to get some testing time today!

    Tested using the forum files and works perfectly! But when I test using my actual URLs, the wait times specified don't seem to work - I'm presuming they don't as during the report loading screen, a drop down appears which I think must be when the code is trying to select 'save'? See picture 1.

    So as you'd expect, i'm ending with errors - See picture 2.

    Testing using the forum files seems to work fine though which is strange.

    If you can shed any light on the problem, i'd appreciate it!

    Thanks again
    Best Wishes
    Mike
    v4Shot1.jpg
    v4Shot2.jpg

  35. #35
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    You have tested what the code does previously on your own URLs and that worked.

    The download bit of the code is still doing exactly what it was doing
    (tested when forum files downloaded without error)

    So I agree with you that the problem is caused by an insufficient delay somewhere
    - and is supported by the specific menu that pops up in your picture
    - "Safety" (begins woth "S") - probably triggered by the "s" in
    SendKeys "%s~"
    The "Safety" menu is probably being triggered because DelayNavigation is too short
    - so change its value from
    Const DelayNavigation = "00:00:02"
    to:
    Const DelayNavigation = "00:00:10"

    As you know internet response time varies greatly from day to day - and today may be a bad day!
    I am afraid that a bit of trial and error is required to tweak the numbers
    - err on the side of caution and be generous with delay times
    Last edited by kev_; 10-19-2017 at 11:13 AM.

  36. #36
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Hi Kev,

    I think the DelayNavigation value should be the seconds value in column C. Each of my reports load in the browser - this is when the time loading varies (a few seconds up to 45 seconds). The sendkeys s should only happen after the time stated in column C has elapsed. The downloads window then appears and the sendkeys s should save the file.

    Hope this makes sense! And thanks again for your time

  37. #37
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Quote Originally Posted by MRedfern View Post
    Hi Kev,

    I think the DelayNavigation value should be the seconds value in column C. Each of my reports load in the browser - this is when the time loading varies (a few seconds up to 45 seconds). The sendkeys s should only happen after the time stated in column C has elapsed. The downloads window then appears and the sendkeys s should save the file.

    Hope this makes sense! And thanks again for your time
    Hi Kev,

    I moved the 'Extra' part of the code up to DelayNavigation and it works perfectly!

    Private Sub DownloadFiles()
    Application.DisplayAlerts = False
    StartTime = Now
    For Each URL In linkList
    'open each link
    Shell (browserPath & " " & URL.Value)
    WaitTime (DelayNavigation) 'sub
    Extra = GetTime(URL.Offset(, 2).Value)
    WaitTime (Extra) 'function
    SendKeys "%s~" '= save file
    WaitTime (DelayDownloadDefault) 'sub
    ValidityCheck 'sub
    Next URL
    Application.DisplayAlerts = True
    End Sub

    I'll do some more tests tomorrow and over the weekend but looks like it's working exactly how I needed!

    Can't thank you enough Kev - you've been invaluable!

    Mike

  38. #38
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Need Help! Macro to click hyperlink, save and replace

    You are welcome - glad you figured it out

    There is another way to do what you want
    - it avoids the unpredictability of SENDKEYS
    - I may experiment with that next week
    - I will PM you if things looks promising

  39. #39
    Registered User
    Join Date
    10-10-2017
    Location
    Daventry, England
    MS-Off Ver
    2016
    Posts
    22

    Re: Need Help! Macro to click hyperlink, save and replace

    Quote Originally Posted by kev_ View Post
    You are welcome - glad you figured it out

    There is another way to do what you want
    - it avoids the unpredictability of SENDKEYS
    - I may experiment with that next week
    - I will PM you if things looks promising
    Cool! Sounds interesting! I'm intrigued

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Html macro to click particular hyperlink in webpage
    By manjulashankar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2016, 09:53 PM
  2. [SOLVED] Macro to run/click a hyperlink in C6
    By Steve_123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2014, 11:21 AM
  3. click on Hyperlink with macro
    By PriyankaGurav in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2013, 04:06 AM
  4. How can I save and eamil an Excel file from the click of a hyperlink
    By peche in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-14-2013, 07:26 AM
  5. Run Macro on Hyperlink click
    By karmaimages in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-24-2012, 03:15 PM
  6. How doyou 'click' a hyperlink with a macro?
    By Wombat in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-21-2009, 02:56 AM
  7. click on variable hyperlink macro
    By yeoye in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2009, 09:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1