Если я правильно прочитал этот комментарий («Дело в том, что мой исходный код должен возвращать 8 разных значений ...»), вы можете попробовать что-то вроде этого, используя Определенный пользователем тип (UDT, обычно известный как Structure
на других языках):
' Define the UDT in the General section of a module
Type MyReturnValues
' Expand the individual UDT members as needed
Value1 As String
Value2 As Long
Value3 As Date
' ... More members, if needed
DocDate As String
End Type
Sub Main()
Dim udtReturn As MyReturnValues
' ```(some code before)```
udtReturn = RemitterParsing()
' Show the results of RemitterParsing()
With udtReturn
Debug.Print "Value1: "; .Value1, "Value2: "; .Value2, "Value3: "; .Value3, "DocDate: "; .DocDate
End With
' ```this goes for 8 different values```
Set objDocDate = objDoc.createElement("PayerDocumentDa")
objRemitt.appendChild objDocDate
objDocDate.Text = DocDate
End Sub
Private Function RemitterParsing() As MyReturnValues
Dim udt As MyReturnValues
OpenPosition = InStr(Range(foundRmt.Address).Offset(2, 0).Value, "PayerDocumentDa>")
closeposition = InStr(Range(foundRmt.Address).Offset(2, 0).Value, "</PayerDocumentDa")
udt.DocDate = Mid(Range(foundRmt.Address).Offset(2, 0).Value, OpenPosition + 16, closeposition - OpenPosition - 16)
' Populate a 2nd UDT member
OpenPosition2 = InStr(Range(foundRmt.Address).Offset(2, 0).Value, "PayerDocumentDa>")
closeposition2 = InStr(Range(foundRmt.Address).Offset(2, 0).Value, "</PayerDocumentDa")
udt.Value1 = Mid(Range(foundRmt.Address).Offset(2, 0).Value, OpenPosition + 16, closeposition - OpenPosition - 16)
' Add random stuff for demonstration
With udt
.Value2 = 123
.Value3 = Now()
End With
' Return the values
RemitterParsing = udt
End Function