Allan Stohn
asked on
VBA check for empty datasource
Hi experts
We are using VBA in Word 2013 to automate letters and so on. Data is exported from our system to csv files. I've run into an issue where the csv file only holds the dataname (first line) but no actual data. When I then run this command:
ActiveDocument.MailMerge.O penDataSou rce Name:=MyDataSource
We get a popup asking to correct the datasource. Is there a way to check if the datasource is empty and then handle it from there, so it doesn't interrupt the script?
(This is the pop-up, that I'm trying to avoid. It's in Danish, sorry for that)
Thx.
Allan
We are using VBA in Word 2013 to automate letters and so on. Data is exported from our system to csv files. I've run into an issue where the csv file only holds the dataname (first line) but no actual data. When I then run this command:
ActiveDocument.MailMerge.O
We get a popup asking to correct the datasource. Is there a way to check if the datasource is empty and then handle it from there, so it doesn't interrupt the script?
(This is the pop-up, that I'm trying to avoid. It's in Danish, sorry for that)
Thx.
Allan
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm afraid that I don't remember seeing your name. I guess you used something more cryptic 10 years ago.
You will have to open the file with something. Since you have the Word application, it seems the best thing to use.
Some warning messages can be suppressed with
You will have to open the file with something. Since you have the Word application, it seems the best thing to use.
Some warning messages can be suppressed with
Application.DisplayAlerts = False
but the 'Header Record Delimiters' dialogue that opens needs an answer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes. Opening it as a text file in FSO is just as good.
ASKER
With inspiration from GrahamSkan I ended up using the posted solution.
ASKER
Fantastic to see your name. I remember you answered some of my question back in the days, maybe 10 years ago or so on ExpertExchange.
Would it be possible to check if the csv has more than on line without opening it in word.