VB脚本 - 从csv文件中删除特殊字符

时间:2017-02-22 15:27:11

标签: replace vbscript special-characters

在我输入的csv文件中,我可能在文件的任何位置都有以下特殊字符。我必须用一些替代文字替换下面的特殊字符。我怎么能在vb脚本中这样做?

  

®³·•½×ΕΕ - ∞∞'“≤≥•

1 个答案:

答案 0 :(得分:0)

我们可以迭代CSV文件的每个单元格,并在每个单元格中验证每个字节,并根据您的要求将其与Ascii值进行比较,如果其Ascii值不在我们期望的值的范围内可以用你需要的任何文字替换它。下面的示例代码

Workbooks.Open("Your CSV file")
for k = 1 to Activeworkbook.Sheets(1).usedrange.rows.count

for j= 1 to Activeworkbook.Sheets(1).usedrange.columns.count
value=Activeworkbook.sheets(1).cells(k,j)
newvalue=""
for i=1 to len(value)-1

temp=mid(value,i,1)
if (Asc(temp)<127 and Asc(temp)>31 )then ' i am just assuming only the values on keyboard should be included any other conditions required for your requirement can be implied here

newvalue=newvalue & temp

else

newvalue=newvalue &"required text"
endif

next

activeworkbook.sheets(1).cells(k,j)=newvalue

next
next