Why CCur gives me error 13: type mismatch?

greg_em

New Member
Joined
Jan 23, 2025
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I'm trying to convert financial MT940 file to workbook with VBA, but I have some problems.

This is my unfinished code:
Rich (BB code):
Option Explicit
Public Referencja As String, IBAN As String, Wyciag As String, Nazwa_skr As String, Pole_salda As String
Public Saldo_poczatkowe As Currency, Saldo_typ As String * 1, Saldo_data_ks As Date, Saldo_waluta As String * 3
Sub Alior_Read_MT940()
Application.DecimalSeparator = ","
ActiveWorkbook.RefreshAll
Dim i As Integer, PATH As String, FileList()
PATH = ThisWorkbook.Sheets("SET").Range("A2").Value
If Right(PATH, 1) <> "\" Then PATH = PATH & "\"
FileList = Worksheets("SET").ListObjects("Pliki").DataBodyRange.Value
For i = LBound(FileList, 1) To UBound(FileList, 1)
    If FileList(i, 1) <> "" Then Call SplitFile(FileList(i, 1), PATH)
    Next i
End Sub

Sub SplitFile(ByVal FileName As String, ByVal PATH As String)
    Application.DecimalSeparator = ","
    Dim char_1
    Dim MT_file As String, text As String
    MT_file = "" & PATH & FileName
   
    Open MT_file For Input Access Read As #1

    Do Until EOF(1)
    char_1 = Input(1, #1)
    text = text & char_1
    Loop
    Close #1
    MsgBox ("tekst: " & text)
   
    '!!! NAGŁÓWEK !!!

    Dim parametry(5) As String, pola_gł(5) As String, i As Integer
    Dim koniec_linii(5) As Long, początek_linii(5) As Long, dł_linii(5) As Long
    parametry(1) = ":20:"
    parametry(2) = ":25:"
    parametry(3) = ":28C:"
    parametry(4) = ":NS:22"
    parametry(5) = ":60F:"
    For i = 1 To UBound(parametry)
        If i = 1 Then
        początek_linii(i) = InStr(text, parametry(i)) + CInt(Len(parametry(i)))
        koniec_linii(i) = InStr(text, Chr$(13))
        dł_linii(i) = koniec_linii(i) - początek_linii(i)
        pola_gł(i) = Mid(text, początek_linii(i), dł_linii(i))
        Else
                If InStr(text, parametry(i)) = 0 Then
                początek_linii(i) = początek_linii(i - 1)
                koniec_linii(i) = koniec_linii(i - 1)
                pola_gł(i) = ""
                Else
                początek_linii(i) = InStr(koniec_linii(i - 1) + 2, text, parametry(i)) + CInt(Len(parametry(i)))
                koniec_linii(i) = InStr(koniec_linii(i - 1) + 2, text, Chr$(13))
                dł_linii(i) = koniec_linii(i) - początek_linii(i)
                pola_gł(i) = Mid(text, początek_linii(i), dł_linii(i))
                End If
        End If
        Next i
    If Not IsEmpty(Pole_salda) Then
        Saldo_typ = Left(Pole_salda, 1)
        Saldo_data_ks = DateSerial(Val("20" & Mid(Pole_salda, 2, 2)), Val(Mid(Pole_salda, 4, 2)), Val(Mid(Pole_salda, 6, 7)))
        Saldo_waluta = Mid(Pole_salda, 8, 3)
        Saldo_poczatkowe = CCur(Mid(Pole_salda, 11))
    End If
    Referencja = pola_gł(1)
    IBAN = pola_gł(2)
    Wyciag = pola_gł(3)
    Nazwa_skr = pola_gł(4)
    Pole_salda = pola_gł(5)
    MsgBox ("Referencja: " & Referencja)
    MsgBox ("IBAN: " & IBAN)
    MsgBox ("Wyciąg: " & Wyciag)
    MsgBox ("Nazwa skrócona" & Nazwa_skr)
    MsgBox ("Pole salda: " & Pole_salda)
    MsgBox ("Typ salda: " & Saldo_typ)
    MsgBox ("Data księgowania: " & Saldo_data_ks)
    MsgBox ("Waluta: " & Saldo_waluta)
    MsgBox ("Saldo początkowe: " & Saldo_poczatkowe)
End Sub

MsgBoxes are using for debugging purpose (do I cut proper text fragment).

I could not publish the original input file, because he contains confidential financial information.
 
I prepared some example file, without confidential information and with some random numbers and names instead:

Rich (BB code):
{:20:0320339
:25:PL05249000050000460000135069
:28C:1
:60F:C250102PLN4361,62
:61:2501020102CN750,00NTRFNONREF//138
Przelew
:86:0510<00p. incoming domestic/internal<10138
<20Z2357 Name Surname oplata za
<21 event Event
<22name 14-27.02.202
<235
<2620250102
<27Name Surname
<28Place. 1/9
<2922-100 CITY
<3012402932
<311111001070309049
<32Name Surname
<3810124028321211002060309049
<63REF420000230068_138

:62F:C250131PLN111,92
:64:C250131PLN111,92
-}
 
Upvote 0
What am I missing here ? The code refers to "Pole_salda" in the If statement and the Currency line but the only place I can see it getting populated is in the code under that.
 
Upvote 0
This is the wrong test to apply to a string variable:

VBA Code:
If Not IsEmpty(Pole_salda) Then

Instead, you could use:

Code:
If Len(Pole_salda) Then
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,253
Members
453,784
Latest member
Chandni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top