VBA文本型数字变成数值

时间:2024-09-29 15:03:08

VBA文本型数字变成数值

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

             Excel.Application excel = new Excel.Application();
//excel.Visible = true;
Excel.Workbook book = excel.Workbooks.Open(path + "\\" + fileName
, 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);
Excel.Workbook book1 = excel.Workbooks.Open(path + "\\Convert"
, 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);
string macroname = "Convert!Convert";
excel.Run(macroname
, 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, 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, Missing.Value, Missing.Value);
book1.Close(false
, Missing.Value, Missing.Value);
Marshal.ReleaseComObject(book1);
book.Close(true
, Missing.Value, Missing.Value);
Marshal.ReleaseComObject(book);
excel.Quit();
Marshal.ReleaseComObject(excel);

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