Forum

Error Handling in V...
 
Notifications
Clear all

Error Handling in VBA

2 Posts
2 Users
0 Reactions
82 Views
(@secretmath)
Posts: 1
New Member
Topic starter
 

Hi, 

 

I have a VBA code that copies data from MS Word documents in a folder and pastes them into an MS Excel file. The folder contains about over 2000 MS word files. The code opens each word file in the folder and looks for two key words, lets call them "FindWord1" and "FindWord2", then copies all the data (including text) that is located between these two keywords from this word file and pastes it into a Excel worksheet. Then moves on to the next Word file in the folder.

Some of these 2000 word documents are missing the two keywords. If the code does not find the key words (either "Findword1" or "Findword2") it returns an error. So only the word documents opened before this error are copied and pasted. Is there a way to log the files names of the word documents that are missing the keywords, skip them and move on to the next file in the folder. 

The code runs fine as is, but I have to manually go and remove the file from the folder for it to go to the next file which is taking a lot of time. I would appreciate any help here. 

Thanks,

N

 
Posted : 10/08/2021 5:37 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Nelly,

Yes, you trap the error and log the filename as you see fit, then continue on with the next file.

See these posts for instructions on error trapping and debugging

Error Handling in VBA • My Online Training Hub

Debugging VBA Code • My Online Training Hub

More Tips for Debugging VBA • My Online Training Hub

Regards

Phil

 
Posted : 11/08/2021 2:07 am
Share: