我发现转换到excel的数据为文本格式,但我需要的是数字格式,我加了一句转换语句,但是不行
Private Sub Command2_Click()
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1) With Adodc1.Recordset
xlsheet.Range("a1").CopyFromRecordset Adodc1.Recordset
xlapp.Visible = True
Columns("a:d").AutoFit
xlapp.columns("d").numberformat= "0"
‘这句转换语句,运行后报实时错误1004 不能设置range的numberformat属性
xlapp.Workbooks.Close
Set xlapp = Nothing
End With
End Sub
请高人指点一下,应该怎么转换格式
Private Sub Command2_Click()
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1) With Adodc1.Recordset
xlsheet.Range("a1").CopyFromRecordset Adodc1.Recordset
xlapp.Visible = True
Columns("a:d").AutoFit
xlapp.columns("d").numberformat= "0"
‘这句转换语句,运行后报实时错误1004 不能设置range的numberformat属性
xlapp.Workbooks.Close
Set xlapp = Nothing
End With
End Sub
请高人指点一下,应该怎么转换格式
用NumberFormatLocal不管用,我试了很多,"1","0000","@" ,程序是不报错了,但转换到excel的数据还是文本的
看上去是数字,但excel的单元格上有一个绿三角,点上去后出现黄色惊叹号,提示此单元中数字为文本格式
xlapp.columns("d").NumberFormatLocal = "0_ "
也用过的,运行后报实时错误1004 不能设置range的numberformat属性
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
With Adodc1.Recordset
xlsheet.Range("a1").CopyFromRecordset Adodc1.Recordset
xlapp.Visible = True
xlsheet.Columns("a:d").AutoFit
xlsheet.Range("Z1").FormulaR1C1 = "1"
xlsheet.Range("Z1").Copy
xlsheet.Columns("D").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
xlsheet.Range("Z1").FormulaR1C1 = ""
xlsheet.SaveAs App.Path & "\test.xls"
xlapp.Workbooks.Close
Set xlapp = Nothing
End WithEnd Sub
不行啊,老大,我这里还是报错:实时错误1004
类range的pastespecial方法无效,是不是我们的vb版本不同啊,我用的是6.0的
应该不是vb版本的问题,你的office是什么版本
[email protected]
发过来
xlshee.cell(i,4)=val(xlsheet(cell(i,4))