编译错误 - 参数不可选

问题描述 投票:1回答:1

我收到错误,因为编译错误:当运行指向该行的vba代码时,参数不可选。 MsgBox(RemoveFirstChar)

码:

Sub test()
Dim Currworkbook As Workbook
Dim CurrWKSHT As Worksheet
Dim Filename As String
Dim BCName As String
Dim Str As String

FFolder = "C:\user"
CurrLoc = "File3"

If CurrrLoc = "File3" Then
    CurrLoc = FFolder & "\" & CurrLoc
    Set FSobj = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    Set FFolderObj = FSobj.GetFolder(CurrLoc)
    If Err.Number > 0 Then
      '
    End If
    For Each BCObj In FFolderObj.Files
        'BCName = Right(BCObj.Name, (Len(BCObj.Name) - InStrRev(BCObj.Name, "\", 1)))
        If IsNumeric(Left(BCObj.Name, 4)) <> True Then
            Call RemoveFirstChar(BCObj.Name)
            'Str = RemoveFirstChar
            MsgBox (RemoveFirstChar)  '--->Error: Compile Error: Argument Not Optional 
        Else
            MsgBox (BCObj.Name)
        End If
    Next

End If



End Sub

Public Function RemoveFirstChar(RemFstChar As String) As String
Dim TempString As String
TempString = RemFstChar
If Left(RemFstChar, 1) = "1" Then
    If Len(RemFstChar) > 1 Then
        TempString = Right(RemFstChar, Len(RemFstChar) - 1)
    End If
End If
RemoveFirstChar = TempString
End Function
excel vba excel-vba compiler-errors compilation
1个回答
1
投票

RemoveFirstChar是一个用户定义的函数,需要一个非可选的字符串作为参数。

Public Function RemoveFirstChar(RemFstChar As String) As String
     ....
End Function

我想你想摆脱Call RemoveFirstChar(BCObj.Name)然后使用,

MsgBox RemoveFirstChar(BCObj.Name)
© www.soinside.com 2019 - 2024. All rights reserved.