Excel VBA - Identification of illegal characters in filenames

  • Thread starter Thread starter magd0095
  • Start date Start date
M

magd0095

I am running a macro in Excel which creates a large number of files wit
filenames taken from cells on a spreadsheet. The filenames correspon
to project names and currently contain characters which cannot be use
in a filename (e.g. "/" or "#").

Is anyone aware of any code which will identify any filenames whic
will not be accepted and strip out the offending character(s)?

Thanks
Mar
 
Mark,

Chip Pearson has posted code like this:

Dim Ndx As Integer
Dim FName As String
Const BadChars = "/$:\'<|>*" ' put your illegal characters here

FName = Range("A1").Text
For Ndx = 1 To Len(BadChars)
FName = Replace$(FName, Mid$(BadChars, Ndx, 1), "_")
Next Ndx

You can modify to include in your code.

HTH,
Bernie
MS Excel MVP
 

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

Back
Top