Link to home
Start Free TrialLog in
Avatar of Allan Stohn
Allan StohnFlag for Denmark

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.OpenDataSource 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?

User generated image(This is the pop-up, that I'm trying to avoid. It's in Danish, sorry for that)


Thx.

Allan
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Allan Stohn

ASKER

Hi GrahamSkan

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.
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
    Application.DisplayAlerts = False

Open in new window

but the 'Header Record Delimiters' dialogue that opens needs an answer
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. Opening it as a text file in FSO is just as good.
With inspiration from GrahamSkan I ended up using the posted solution.