Avatar of Allan Stohn
Allan Stohn
Flag 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?

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


Thx.

Allan
VBAMicrosoft WordMicrosoft Office

Avatar of undefined
Last Comment
Allan Stohn

8/22/2022 - Mon
SOLUTION
GrahamSkan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
GrahamSkan

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
Allan Stohn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
GrahamSkan

Yes. Opening it as a text file in FSO is just as good.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Allan Stohn

ASKER
With inspiration from GrahamSkan I ended up using the posted solution.