如果instr(mymessage,“I”)<> 0然后=编译器错误? [英] If instr(mymessage, "I'") <> 0 then = compiler bug ?

查看:70
本文介绍了如果instr(mymessage,“I”)<> 0然后=编译器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中编写了一个可视化的基本宏

我正在寻找字符串我就是我要用

使用我进行编码绕过文字



我尝试过:



I have written a visual basic macro in Excel
I am looking for the strings I'm I'll I'd
Coding as above using "I'" bypasses the text

What I have tried:

Searching for I'm separately does not work either
Using ""I'm"" gives a compilation error
Any workarounds greatly received for 67 year old coder with 50 years IT experience.
Darrell

推荐答案

绝对不是编译器错误。 VBA已经存在了几十年,所以这种可能性极其遥远,而且你没有边缘做任何事情。



这对我来说是预期的:

Definitely not a compiler bug. VBA has been around for decades so that possibility is extremely remote and you're not doing anything "on the edge".

This works as expected for me:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim message

    message = "I'm OK"
    
    If InStr(message, "I'") <> 0 Then
        MsgBox "Found"
    Else
        MsgBox "Not Found"
    End If
End Sub



您是否在代码顶部使用了选项比较?


Have you used "Option Compare" at the top of your code?


嗯...用单引号替换双引号,所以我将替换为我将,一切都会好的。请参阅:



Well... Replace double quotation marks with single, so ""I'll"" should be replaced with "I'll" and everything will be fine. See:

Option Explicit


Sub test()
    Dim Strings2Find As Variant
    Dim Text2SearchIn As String
    Dim i As Integer, j As Integer
    
    Text2SearchIn = "I'm glad i can see you. I'd like to introduce some one to you. I'll be very happy, if you'll..." 'text is not important ;)
    Strings2Find = Array("I'm", "I'll", "I'd")
    
    
    For i = LBound(Strings2Find) To UBound(Strings2Find)
        Do
            j = InStr(j + 1, Text2SearchIn, Strings2Find(i))
            If j > 0 Then MsgBox "'" & Strings2Find(i) & "' has been found on position: " & j & vbCr & _
            "'" & Text2SearchIn & "'", vbOKOnly, "Success!"
        Loop While j > 0
    Next


End Sub


这篇关于如果instr(mymessage,“I”)&lt;&gt; 0然后=编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆