Detect and delete non-text character?

E

Ed

I query an old database which yields an Access-like table output. I convert
this to a tab-delimited DOS .txt file. I then open this text file in Word
and run a macro which loops through the text file making separate Word docs.
The first steps of the loop are to select the first grouping (a report
number), and use it to compare each line until it changes; this selection is
also used as the file name when the new document is saved.



Since this takes about two hours to run, I set it to start when I'm leaving
for the day, and let a separate program shut off my computer. One day I
forgot to set my shut-off, and noticed the macro was stalled on an error. A
bit of investigation showed that my converted .txt file has a garbage
non-text character as the last line (it looks like a little square). The
actual query output ends in a filled table row, so apparently the conversion
adds this below the last line of text.



I'm thinking I should delete that character before running the rest of the
macro, just to avoid the error. Since I can't guarantee that this character
will always be there, or will only be just one character or just one line, I
'm wondering how best to approach this. Can I add something that looks at
the initial selection to see if it is valid text - if yes, continue - if
not, delete and end sub? Or is there a better way?



Ed
 
C

Cindy Meister -WordMVP-

Hi Ed,
I'm thinking I should delete that character before running the rest of the
macro, just to avoid the error. Since I can't guarantee that this character
will always be there, or will only be just one character or just one line, I
'm wondering how best to approach this.
Test if this always gives you the same result if you have the character
selected:

Sub GetCharNumber()
MsgBox AscW(Selection.Text)
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top