gpt4 book ai didi

vba - 编译错误-参数不是可选的

转载 作者:行者123 更新时间:2023-12-02 10:46:15 26 4
gpt4 key购买 nike

当运行指向该行的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

最佳答案

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

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

我认为您想摆脱 Call RemoveFirstChar(BCObj.Name)然后使用,
MsgBox RemoveFirstChar(BCObj.Name)

关于vba - 编译错误-参数不是可选的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49133154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com