Hier ist der Code ich versuche zu laufen, kann ich nichts falsch finden, warum kann ich String nicht in Funktion mit String Argument übergeben? Es sagt mir immer ByRef Argument Type Mismatch.VBA ByRef Argument Typ Mismatch string in string
Ich versuchte andere Antworten diesbezüglich, ich kann immer noch nicht die Lösung finden. Die Hoffnung kann hier ein wenig helfen.
Hauptverfahren:
Sub Macro()
Dim test As String
Dim arr() As String
Dim CompiledText As String
Dim temporary As String
Dim i As Long
Dim ab As String
Dim marker As Long
market = 0
test = Range("A1").Value
arr = Split(test, Chr(10))
test = ""
CompiledText = ""
For i = 0 To UBound(arr)
If (Left(arr(i), 1) <> "#") Then
If (Trim(test) <> "") Then
test = test & vbCrLf
End If
test = test & arr(i)
If (InStr(arr(i), "ATTRS(") <> 0) Then
If (CompiledText <> "") Then
CompiledText = CompiledText & vbCrLf
End If
temporary = arr(i)
CompiledText = CompiledText & GrabATTRS(CStr(temporary))
ElseIf (InStr(arr(i), "ATTRN(") <> 0) Then
If (CompiledText <> "") Then
CompiledText = CompiledText & vbCrLf
End If
temporary = arr(i)
CompiledText = CompiledText & GrabATTRN(CStr(temporary))
ElseIf (InStr(arr(i), "DB(") <> 0) Then
If (CompiledText <> "") Then
CompiledText = CompiledText & vbCrLf
End If
temporary = arr(i)
CompiledText = CompiledText & GrabDB(CStr(temporary))
End If
Else
If (marker <> i - 1) Then
arr(marker) = arr(marker) & vbCrLf & CompiledText
CompiledText = ""
End If
marker = i
End If
Next i
test = ""
For i = 0 To UBound(arr)
If (i > 0) Then
test = test & vbCrLf
End If
test = test & arr(i)
Next i
Range("B1").Value = test
End Sub
Funktion aufgerufen wird, dass nicht richtig funktioniert:
Function GrabATTRS(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "ATTRS(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
attib = onlyChar(Split(temp, ",")(UBound(Split(temp, ",")) - 1))
GrabATTRS = "#From dimension " & dimension & " pointing to " & attrib
End Function
Function GrabATTRN(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "ATTRN(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
attib = onlyChar(Split(temp, ",")(UBound(Split(temp, ",")) - 1))
GrabATTRN = "#From dimension " & dimension & " pointing to " & attrib
End Function
Function GrabDB(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "DB(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
GrabDB = "#From " & dimension & " Cube"
End Function
Diese eine Funktion überprüft werden, überspringen kann, da es funktioniert gut
Function onlyChars(S As String) As String
Dim i As Integer
retval = ""
For i = 1 To Len(S)
If Mid(S, i, 1) <> "'" Then
retval = retval + Mid(S, i, 1)
End If
Next i
onlyChars = retval
End Function
Option Explicit
ty es funktioniert!, Ich wusste nicht, dass ich sie in Zeichenfolge platzieren muss zuerst – Chrishadianto
verarbeitet werden @Chrishadianto Sie sind willkommen! Ja, wenn Sie die Parameter 'ByRef' übergeben, muss der Typ des Parameters' String' sein (und nicht 'Variant', das von' Split' zurückgegeben wird). – dee