如果语句错误!=
If statement error !=
我有这个宏:
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 = ","
.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 语句以防止用户在未选择文本的情况下应用它。
您是否将 VBA 语法与 javascript 等其他语言混淆了? VBA 使用 <>
作为不等于运算符。 !=
被 javascript 和其他一些 C 风格的语言使用。
If Selection.Start <> Selection.End Then
我有这个宏:
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 = ","
.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 语句以防止用户在未选择文本的情况下应用它。
您是否将 VBA 语法与 javascript 等其他语言混淆了? VBA 使用 <>
作为不等于运算符。 !=
被 javascript 和其他一些 C 风格的语言使用。
If Selection.Start <> Selection.End Then