从Excel VBA结果中删除引号可以通过以下几种方法实现:
Sub RemoveQuotes()
Dim result As String
Dim originalString As String
originalString = "This is a 'sample' string."
result = Replace(originalString, "'", "")
MsgBox result
End Sub
在上述示例中,原始字符串中的单引号被替换为空字符串,最终结果将弹出一个对话框显示为:"This is a sample string."
Sub RemoveQuotes()
Dim result As String
Dim originalString As String
Dim i As Integer
originalString = "This is a 'sample' string."
For i = 1 To Len(originalString)
If Mid(originalString, i, 1) <> "'" Then
result = result & Mid(originalString, i, 1)
End If
Next i
MsgBox result
End Sub
在上述示例中,循环遍历原始字符串的每个字符,如果字符不是引号,则将其添加到结果字符串中。最终结果将弹出一个对话框显示为:"This is a sample string."
Sub RemoveQuotes()
Dim result As String
Dim originalString As String
Dim regex As Object
originalString = "This is a 'sample' string."
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = "'"
result = regex.Replace(originalString, "")
MsgBox result
End Sub
在上述示例中,创建了一个正则表达式对象,并设置其模式为引号字符。然后使用Replace方法将原始字符串中的引号替换为空字符串。最终结果将弹出一个对话框显示为:"This is a sample string."
以上是三种常见的方法来从Excel VBA结果中删除引号。根据具体的需求和情况,选择适合的方法即可。
领取专属 10元无门槛券
手把手带您无忧上云