VBA Code Stops on Downloading File message

hellfire45

Active Member
Joined
Jun 7, 2014
Messages
462
So I have this code below. It is opening a text file and pasting its contents into excel. Simple.

This particular workbook loops through around 1000 text files and compiles them into a single sheet. The problem is that the code has been stopping at the code below when it opens the file. It'll just sit there on the downloading screen. This only happens about every 20th file but its a big issue. Any idea why this is happening? It's essentially the little box with the bar that opens when the computer is opening up a file. Thanks so much!

Anyway to stop this from happening? I already have application.displayalerts = false at the start of the automations first module.

Code:
ChDir strFolderWorkbooks.OpenText FileName:=strFolder & filename_lessext & target_ext _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It looks like someone may have altered some code. The 'ChDir' syntax is
Code:
ChDir "C:\"
The function followed by the directory path.
In your code snippet, everything after ChDir looks like a 'Workbooks.OpenText' statement, which would probably throw an error because of syntax.
You might be able to fix it by putting the ChDir on a separate line, if really needed, and put the Workbooks.OpenText' statement beneath it on a separate line.
But you would need the path for the ChDir statement.
 
Last edited:
Upvote 0
Sorry about that, I think I actually just pasted it incorrectly. It is truly as seen below.

Code:
ChDir strFolder

Workbooks.OpenText FileName:=strFolder & filename_lessext & target_ext _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

This code does not error. It just sometimes gets stuck loading these files. The green bar on the "downloading" window fills up and then it gets stuck until I hit cancel. I'm not sure why this happens but I need it to not happen. It only happens like 5% of the time. Any ideas friends?
 
Last edited:
Upvote 0
Sorry about that, I think I actually just pasted it incorrectly. It is truly as seen below.

Code:
ChDir strFolder

Workbooks.OpenText FileName:=strFolder & filename_lessext & target_ext _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

This code does not error. It just sometimes gets stuck loading these files. The green bar on the "downloading" window fills up and then it gets stuck until I hit cancel. I'm not sure why this happens but I need it to not happen. It only happens like 5% of the time. Any ideas friends?

That paricular snippet would not cause a problem, in and of itself, but if you have a large amount of files and the overall code is not written to relieve the memory storage on each iteration, it could just overload the system and it will shut down. Things to consider are being sure to close each source file as it is completed, resetting object varibles to 'Nothing' on each iteration and any other type of memory dump that can be done without losing your essential variables.
 
Upvote 0

Forum statistics

Threads
1,216,730
Messages
6,132,401
Members
449,725
Latest member
Enero1

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