如果声明错误!=

时间:2015-08-14 08:55:04

标签: vba ms-word

我有这个宏:

Sub fixComma()
'
' fixComma Macro
'
'
'  If (Selection.Start != Selection.End) Then
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.LanguageID = wdEnglishUS
    With Selection.Find
        .Text = "([0-9]).([0-9])"
        .Replacement.Text = "\1,\2"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   '  Else
     '  MsgBox "Nothing is selected, Macro terminated"
  '  End If
End Sub

如果我取消注释if-else语句,我会收到以下错误:

Compile Error:
type declaration character does not match declared data type

记录了宏,我添加了if语句,以防止用户在不选择文本的情况下应用它。

1 个答案:

答案 0 :(得分:3)

您是否将VBA语法与javascript等其他语言混淆? VBA使用<>作为不等于运算符。 !=由javascript和其他一些C风格的语言使用。

If Selection.Start <> Selection.End Then