几个月前,我为我的公司写了一个小万客隆,到现在为止还不错。最近(也许是因为我们更新了Office版本)存在一个错误,excel在打印语句中添加了新行。
码:
outputString = value1 & " " & value2 & " " & value3 & " " & value4 & " " & value5 & " " & user & " " & date
曾经给我这个输出:
22 S ***/***s 9932256 B*****t Fatma 811 R******r Alexander 27.12.2019
现在给我这个输出:
22 S ***/***s 9932256 B*****t Fatma 811 R******r Alexander
27.12.2019
如您所见,excel添加了换行符。
有人可以告诉我这里发生了什么吗?
编辑:
解:
Excel在使用后添加新行:
用户= Application.UserName
也许这是由于我们的Office更新造成的。因此,我只是提取了子字符串并剪切了最后一个字符,现在可以正常工作了。
当文档说明用户名时,Application.Username返回。因为Read/write
确实会发生这样的情况,您将获得包含vbLf
或的用户名vbCrLf
。看下面的例子
Sub UserName_VbCrlf()
Dim origUser As String
Dim user As String
' Be careful when testing as it replaces your username!!
' Maybe you save it first
origUser = Application.UserName
Application.UserName = "Storax" & vbLf & "Home adress"
user = Application.UserName
' This will give different lengths
Debug.Print Len(user), Len(Replace(user, vbLf, ""))
' Restore original username
Application.UserName = origUser
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句