Attribute VB_Name = "dima"
Sub Init1(s as string)
    Application.CommandBars.Add(Name:="Печать1", Position:=msoBarTop, Temporary:=True).Visible = True

    With Application.CommandBars("Печать1").Controls.Add(Type:=msoControlButton, _
        Before:=1)
        .FaceId = 190
        .Style = msoButtonIcon
        .Caption = "Пересчитать для чеков"
        .OnAction = "ReCalc"
    End With


End Sub


Public Sub Recalc()
Dim s As Object
Dim summ As Double
Dim i As Integer, j As Integer, k As Integer
    For Each s In Application.Sheets
        s.Activate
        i = 11
        j = 7
	k = 0
        summ = 0
        While VBA.Trim(s.Cells(i, j - 1).Text) <> "ИТОГО:"
            summ = summ + s.Cells(i, j).Value
            k = k + 1
	    s.Cells(i, 1) = k
            i = i + 1
        Wend
        s.Cells(i, j) = summ
        s.Cells(i + 1, 1) = numToStr(summ, True, True, True)
    Next
'    Stop
End Sub

Function numToStr(nm_num As Double, _
            nm_propis As Boolean, _
            nm_padeg As Boolean, _
            nm_equ As Boolean) As String
Dim nm_sn As String, nm_snum As String, nm_cs As String, nm_SSP As String, _
    nm_i As Integer, nm_c1 As Integer, nm_c2 As Integer, nm_c3 As Integer, nPosPoint As Integer
Dim nm_ST(7) As String ' Массив окончаний в зависимости от падежа
  nm_ST(1) = "рубль       рубля       рублей      "
  nm_ST(2) = "тысяча      тысячи      тысяч       "
  nm_ST(3) = "миллион     миллиона    миллионов   "
  nm_ST(4) = "миллиард    миллиарда   миллиардов  "
  nm_ST(5) = "триллион    триллиона   триллионов  "
  nm_ST(6) = "триллиард   триллиарда  триллиардов "
Dim nm_SR(10) As String ' Массив названий цифр разных порядков
  nm_SR(1) = "                                                десять    "
  nm_SR(2) = "сто         десять      один        одна        одиннадцать"
  nm_SR(3) = "двести      двадцать    два         две         двенадцать"
  nm_SR(4) = "триста      тридцать    три         три         тринадцать"
  nm_SR(5) = "четыреста   сорок       четыре      четыре      четырнадцать"
  nm_SR(6) = "пятьсот     пятьдесят   пять        пять        пятнадцать"
  nm_SR(7) = "шестьсот    шестьдесят  шесть       шесть       шестнадцать"
  nm_SR(8) = "семьсот     семьдесят   семь        семь        семнадцать"
  nm_SR(9) = "восемьсот   восемьдесят восемь      восемь      восемнадцать"
  nm_SR(10) = "девятьсот   девяносто   девять      девять      девятнадцать"
Dim nm_skop


' Массив для учета падежа в зависимости от последней цифры
  nm_SSP = "3           1           2           2           2           3           3           3           3           3           "
' Начало
  nm_sn = ""
  nm_snum = Trim(Format(nm_num, "###0.00"))
  nPosPoint = InStr(nm_snum, Mid(Format(0.1, "#.0"), 1, 1))
  If nm_propis Then
    nm_skop = Mid(nm_snum, nPosPoint + 1, 2)
    nm_snum = "00" + Mid(nm_snum, 1, nPosPoint - 1)
    nm_i = Int(Len(nm_snum) / 3)
    nm_snum = Mid(nm_snum, Len(nm_snum) - nm_i * 3 + 1, nm_i * 3)
    If nm_snum = "000" And nm_i = 1 Then
        nm_sn = "Ноль рублей "
    Else
        Do While nm_i > 0
            nm_c2 = Int(Val(Mid(nm_snum, 2, 1)))
            nm_c3 = Int(Val(Mid(nm_snum, 3, 1)))
            nm_cs = Trim(N_SS_(nm_SR(Int(Val(Mid(nm_snum, 1, 1))) + 1), 1) + " " + _
                    Trim(IIf(nm_c2 = 1, N_SS_(nm_SR(nm_c3 + 1), 5), _
            N_SS_(nm_SR(nm_c2 + 1), 2) + " " + IIf(nm_i = 2, N_SS_(nm_SR(nm_c3 + 1), 4), N_SS_(nm_SR(nm_c3 + 1), 3)))))
            If (nm_cs <> "") Or (nm_i = 1) Then
                nm_sn = Trim(nm_sn + nm_cs) + " " + IIf(nm_c2 = 1, N_SS_(nm_ST(nm_i), 3), _
                        N_SS_(nm_ST(nm_i), Val(N_SS_(nm_SSP, nm_c3 + 1)))) + " "
            End If
            nm_snum = IIf(nm_i > 1, Mid(nm_snum, 4, (nm_i - 1) * 3), "")
            nm_i = nm_i - 1
        Loop
    End If
    If Not (nm_equ And (nm_skop = "00")) Then
        If (Not nm_padeg) Or (Int(Val(Mid(nm_skop, 1, 1))) = 1) Or (Val(N_SS_(nm_SSP, Int(Val(Mid(nm_skop, 2, 1))) + 1)) = 3) Then
            nm_sn = nm_sn + nm_skop + " копеек"
        Else
            If Int(Val(Mid(nm_skop, 2, 1))) = 1 Then
                nm_sn = nm_sn + nm_skop + " копейка"
            Else
                nm_sn = nm_sn + nm_skop + " копейки"
            End If
        End If
    End If
    If nm_num < 0 Then
        nm_sn = "минус " & nm_sn
    End If
  Else
    nm_sn = IIf((Mid(nm_snum, Len(nm_snum) - 1, 2) = "00") And nm_equ, _
            Mid(nm_snum, 1, Len(nm_snum) - 3) + " =", nm_snum)
  End If
  numToStr = UCase(Mid(nm_sn, 1, 1)) + LCase(Mid(nm_sn, 2, Len(nm_sn) - 1))
End Function

Function N_SS_(ss_st As String, ss_n As Integer) As String
    N_SS_ = Trim(Mid(ss_st, (ss_n - 1) * 12 + 1, 12))
End Function

