jdc1944
asked on
Replacing Reserved Characters in a Varible
I have a table in word where one of the cells in each row holds a name of a file to be created.
Currently my VB code goes through each row looking in this cell, gets the contents and stores this in a varible, opens a word template and then saves the template as whatever has been written in the cell.
No matter how many times i tell the users, they always forget they cannot use characters like ?\/<>: in this cell because they are not allowed in file names. This obvisouly causes my code to error.
What i want it to do is check each character in the string for these reserved characters and if it finds one replace it with a hyphen so the code can carry on and save the template.
Im been messing around with InStr and Replace methods but im not getting very far.
Anyone able to help me?
Currently my VB code goes through each row looking in this cell, gets the contents and stores this in a varible, opens a word template and then saves the template as whatever has been written in the cell.
No matter how many times i tell the users, they always forget they cannot use characters like ?\/<>: in this cell because they are not allowed in file names. This obvisouly causes my code to error.
What i want it to do is check each character in the string for these reserved characters and if it finds one replace it with a hyphen so the code can carry on and save the template.
Im been messing around with InStr and Replace methods but im not getting very far.
Anyone able to help me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, both of them do just the job
Welcome.
~bp
~bp
strFile = Replace(strFile, "?", "-")
strFile = Replace(strFile, "\", "-")
strFile = Replace(strFile, "/", "-")
strFile = Replace(strFile, "<", "-")
strFile = Replace(strFile, ">", "-")
strFile = Replace(strFile, ":", "-")
~bp