.CopyFromRecordset
将字符串写入Excel工作表。此记录集包含类似日期和数字的字符串,如
和
2018年8月9日
我最近添加了一些额外的处理来调整一些单元格值。但是,当将值写回单元格时,我无法保留它们的当前状态(字符串,格式:常规,没有前导撇号)。
Public Sub MCVE()
With Range("A1")
Debug.Print .Value '09-08-2018
Debug.Print .Value2 '09-08-2018
Debug.Print VarType(.Value) = vbString 'True
Debug.Print .NumberFormat 'General
Debug.Print .PrefixCharacter 'Zero-length string
.Value = .Value 'I want to manipulate the value here too
'.Value2 = .Value2 'Yields the same result
Debug.Print .Value '08-09-2018
Debug.Print .Value2 '43351
Debug.Print VarType(.Value) = vbString 'False
Debug.Print .NumberFormat 'm/d/yyyy
Debug.Print .PrefixCharacter 'Zero-length string
End With
End Sub
.NumberFormat
到
@
强迫它发短信,但是
和
.PrefixCharacter
更改,当将其导入到另一个程序中时,这将导致进一步的麻烦。我也可以在指定字符串之前用撇号填充它,但这会改变
.前缀字符
我也是。
我试过用
.Value2
而不是
.Value
,没有区别。
.Text
Application.Calculation = xlCalculationManual
也没有影响。