'##ModelId=40CE7DA50226
Public Function GoDoOffer() As Boolean
Dim i As Long, j As Long
Dim PathF As String
Dim sum As Double
Dim temps As String
Dim FullCount As Long
FullCount = 0
j = 0
sum = 0
PathF = App.Path & "\Offers\"
If mvarInfoForOffers Is Nothing Then Exit Function
If Not ActivateWord Then Exit Function

WordObj.Visible = True

If Not ReadTitle Then
    Call DefaultTitle
End If

If Not ReadCaption Then
    Call DefaultCaption
End If

On Error GoTo labFileName
Open PathF & mvarNameZakazForFileName & ".txt" For Output As #1
'    Print #1, ""
Print #1, strTitle(0)
If Len(mvarNameZakaz) > 0 Then
    Print #1, Replace(strTitle(1), "_____*_______", mvarNameZakaz, 1, -1, vbTextCompare)
End If
If Len(mvarNameZakazchik) > 0 Then
    Print #1, Replace(strTitle(3), "_____*_______", mvarNameZakazchik, 1, -1, vbTextCompare)
End If
If Len(mvarAddress) > 0 Then
    Print #1, Replace(strTitle(4), "_____*_______", mvarAddress, 1, -1, vbTextCompare)
End If
If Len(mvarPhoneZakazchik) > 0 Then
    Print #1, Replace(strTitle(5), "_____*_______", mvarPhoneZakazchik, 1, -1, vbTextCompare)
End If

Dim Info As clsInfoForOffer
'PathF = PathF & "Offer" & CStr(j) & ".bmp"
For Each Info In mvarInfoForOffers
    With Info
        If Not .PictureDesign Is Nothing Then
            SavePicture .PictureDesign, PathF & "Offer" & CStr(j) & ".bmp"
        Else
            MsgBox "      ." _
                & vbCrLf & "  ", vbInformation Or vbOKOnly, ""
            Exit Function
        End If
    End With
    Print #1, "[picture]"
    Print #1, PathF & "Offer" & CStr(j) & ".bmp"
    j = j + 1
    For i = 0 To UBound(strCaption) - 1
        If Len(Info.Item(i)) > 0 Then
            If 6 = i And "1" = Info.Item(i) Then
                Print #1, Replace(strCaption(i), "__*__", Info.Item(i), 1, -1, vbTextCompare)
'                MsgBox Format(Date, "dd mmmm yyyy") 'VBA.FormatDateTime(Date, 1)
                temps = Replace(strCaption(i + 1), "__*__", Info.Item(i + 1), 1, -1, vbTextCompare)
                temps = Replace(temps, "  ", " ", 1, -1, vbTextCompare)
                Print #1, temps
                i = UBound(strCaption) + 2
            Else
                Print #1, Replace(strCaption(i), "__*__", Info.Item(i), 1, -1, vbTextCompare)
            End If
        End If
    Next i
    FullCount = FullCount + Info.Item(6)
    sum = sum + Info.Item(8)
Next
Print #1, vbCrLf
Print #1, "     - " _
                & CStr(FullCount) & " ."
Print #1, "    - " _
                & Format(sum, "**#,##0.00") & " ."
Close #1
SaveSetting "ViewDesign", "Offer", "Offer", PathF & mvarNameZakazForFileName & ".txt"
On Error GoTo labWord
'Set WordDoc = WordObj.Documents.Add(App.Path & "\Offer.dot")
Set WordDoc = WordObj.Documents.Add(Template:= _
        App.Path & "\Offer.dot", NewTemplate:=False, DocumentType:=0)
WordObj.Run "NewOffer" ', PathF & mvarNameZakazForFileName & ".txt"
Set WordDoc = Nothing
Set WordObj = Nothing

'WordObj.Options.SavePropertiesPrompt = False
'On Error GoTo labFileName
'WordDoc.SaveAs PathF & mvarNameZakazForFileName & ".doc"
'WordObj.Options.SavePropertiesPrompt = True
'
'With WordObj.Selection
'    .TypeText Text:=strTitle(0)
'    .ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
'    .MoveLeft Unit:=wdCharacter, Count:=Len(strTitle(0)), Extend:=wdExtend
'    .font.Size = 18
'    .EndKey Unit:=wdLine
'    .TypeParagraph
'    .TypeParagraph
'    .TypeParagraph
'    .font.Size = 12
'    .ParagraphFormat.Alignment = 0 'wdAlignParagraphLeft
'    .TypeText Text:=Replace(strTitle(1), "_____*_______", mvarNameZakaz, 1, 4, vbTextCompare)
'    .TypeParagraph
'    .TypeParagraph
'    .TypeText Text:=strTitle(2)
'    .TypeParagraph
'    .TypeParagraph
'    .TypeText Text:=Replace(strTitle(3), "_____*_______", mvarNameZakazchik, 1, 4, vbTextCompare)
'    .TypeParagraph
'    .TypeParagraph
'    .TypeText Text:=Replace(strTitle(4), "_____*_______", mvarAddress, 1, 4, vbTextCompare)
'    .TypeParagraph
'    .TypeParagraph
'    .TypeText Text:=Replace(strTitle(5), "_____*_______", mvarPhoneZakazchik, 1, 4, vbTextCompare)
'    .TypeParagraph
'End With

'Dim Info As clsInfoForOffer
'PathF = PathF & "Offer.bmp"
'For Each Info In mvarInfoForOffers
'    With Info
'        SavePicture .PictureDesign, PathF
'    End With
'    With WordObj
'        With .Selection
'            With .InlineShapes
'                .AddPicture PathF
''                With .AddPicture(PathF) '(FileName As String, [LinkToFile], [SaveWithDocument], [Range]) As InlineShape
''                    With .Fill
''                        .Visible = 0 'msoFalse
''                        .Solid
''                        .Transparency = 0#
''                    End With
''                    With .Line
''                        .Weight = 0.75
''                        .Transparency = 0#
''                        .Visible = 0 'msoFalse
''                    End With
''                    .LockAspectRatio = -1 'msoTrue
''        '            .Height = 85.05
''        '            .Width = 113.4
''                    With .PictureFormat
''                        .Brightness = 0.5
''                        .Contrast = 0.5
''                        .ColorType = 1 'msoPictureAutomatic
''                        .CropLeft = 0#
''                        .CropRight = 0#
''                        .CropTop = 0#
''                        .CropBottom = 0#
''                    End With
''                End With
'            End With
'            .TypeParagraph
'            .TypeParagraph
'            For i = 0 To UBound(strCaption) - 1
'                .TypeParagraph
'                .TypeText Text:=Replace(strCaption(i), "__*__", Info.Item(i), 1, -1, vbTextCompare)
'                .TypeParagraph
'            Next i
'
'            sum = sum + Info.Item(8)
'        End With
'    End With
'Next
'With WordObj.Selection
'    .TypeParagraph
'    .TypeText Text:="      - " & CStr(sum) & " ."
'    .HomeKey Unit:=wdLine, Extend:=wdExtend
'    .font.Size = 16
'    .font.Bold = wdToggle
'    .EndKey Unit:=wdLine
'End With
Exit Function

labFileName:
mvarNameZakazForFileName = mvarNameZakazchik & g_GenerateId.NowForFileName
Resume
labWord:
Debug.Print "Error in WordObj"
Resume Next
End Function
