VBA文本型数字变成数值

时间:2022-11-04 22:19:50

VBA文本型数字变成数值

 

sub test()
with activesheet
  .usedrange.numberformatlocal=""
  .usedrange=.usedrange.value
end with
end sub
一般运行一次就可以将全部文本型数字变成数值型了

 1             Excel.Application excel = new Excel.Application();
 2             //excel.Visible = true;
 3             Excel.Workbook book = excel.Workbooks.Open(path + "\\" + fileName
 4                                 , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
 5             Excel.Workbook book1 = excel.Workbooks.Open(path + "\\Convert"
 6                 , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
 7             string macroname = "Convert!Convert";
 8             excel.Run(macroname
 9                 , Missing.Value
10                 , Missing.Value
11                 , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value
12                 , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value
13                 , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
14             book1.Close(false
15                 , Missing.Value, Missing.Value);
16             Marshal.ReleaseComObject(book1);
17             book.Close(true
18                 , Missing.Value, Missing.Value);
19             Marshal.ReleaseComObject(book);
20             excel.Quit();
21             Marshal.ReleaseComObject(excel);

本文来自 http://club.excelhome.net/thread-648740-1-1.html