Hi Everyone,
Here is my current issue that I am trying to solve - I have code that follows hyperlinks from my unread emails using the chrome browser using a shell command. The code will loop through opening the hyperlink from the emails and quickly go one to the next. The issue with this is that upon opening that link is it kicks off a download. I need VBA to wait until that file lands in the Downloads Folder in order to further manipulate it before moving onto the next email in in the folder.
My initial thought was to obtain the count of files in the folder (ex there are 5 files in the folder at the start) and make excel wait until the count of files in the folder is +1. Below is the snippet of code that I have found - sourced from FileSystemObject in VBA – Explained
I do not understand how to execute on my thought to force excel to wait for the file to download and would greatly appreciate any help on this problem or even pointing me in the right direction. I also tried to use Application.Wait to pause the code for 10 seconds but that method was unstable and I am looking for a better way like my thought above.
Here is my current issue that I am trying to solve - I have code that follows hyperlinks from my unread emails using the chrome browser using a shell command. The code will loop through opening the hyperlink from the emails and quickly go one to the next. The issue with this is that upon opening that link is it kicks off a download. I need VBA to wait until that file lands in the Downloads Folder in order to further manipulate it before moving onto the next email in in the folder.
My initial thought was to obtain the count of files in the folder (ex there are 5 files in the folder at the start) and make excel wait until the count of files in the folder is +1. Below is the snippet of code that I have found - sourced from FileSystemObject in VBA – Explained
Code:
'creating download folder to check the count of items in folder
Dim DownloadFolderPath As String
Dim DownloadFolder As Object
Dim fso As Object 'FileSystemObject
Dim DownloadFiles As Object 'File - not sure if correct
Dim DownloadCount As Integer
DownloadCount = 0
DownloadFolderPath = "C:\Users\RandomPerson\Downloads\"
Set fso = CreateObject("Scripting.FileSystemObject") 'New FileSystem Object
Set DownloadFolder = fso.GetFolder(DownloadFolderPath)
Set DownloadFiles = fso.GetFolder(DownloadFolderPath).Files
For Each DownloadFiles In DownloadFolder.Files
If DownloadFiles.Attributes <> 34 Then 'not sure what the 34 stand for I think it is probably a status like not blank ?
DownloadCount = DownloadCount + 1
End If
Next DownloadFiles
Debug.Print DownloadCount
I do not understand how to execute on my thought to force excel to wait for the file to download and would greatly appreciate any help on this problem or even pointing me in the right direction. I also tried to use Application.Wait to pause the code for 10 seconds but that method was unstable and I am looking for a better way like my thought above.
Last edited: