Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Process WordDoc (vb6)

    I need a little help on a doc conversion.
    Some time ago Hans helped me extensively with a project which converts a local doc and makes the text doc into a letterheaded document.
    Its worked for a few years bit something seems to have changed.
    With the attached the top half is the "Before doc and under the thick line is the after doc.
    The word PROFORMA-INVOICE is removed and leaves a capital M to the left.
    There may be more than one version of the above word on the original doc to convert which may have to come into consideration such as :
    PROFORMA-INTERNAL-USE-ONLY
    PROFORM-AS-INSURER-INVOICE
    etc
    The code I have is below which converts the document.
    Can you help?


    Private Sub procSWInvoice_Click(Index As Integer)
    HandleWordDoc "SWInvoice", Me.MAPIMessages2, Me.MAPISession2
    End Sub


    Public Sub ProcessWordDoc(strFile As String, JN As String, strType As String)
    Dim oWord As Object
    Dim oDoc As Object
    frmWait.Show
    ' Start Word
    Set oWord = CreateObject("Word.Application")

    ' Create document based on template
    Set oDoc = oWord.documents.Add("C:MM-UtilitiesLongtonHeader.dot")
    ' Import report
    oWord.Selection.InsertFile strFile, , False
    ' Process document
    oWord.Selection.HomeKey 6
    ' Delete initial returns
    Do While Asc(oWord.Selection) < 32
    oWord.Selection.Delete 1
    Loop
    With oWord.Selection.Find


    .Execute "^p^p^p^p^p^wINVOICE", , , , , , , 1, , _
    "^m INVOICE", 2
    .Execute "^p^p^p^p^p^wESTIMATE", , , , , , , 1, , _
    "^m ESTIMATE", 2
    .Execute Chr(26), , , , , , , 1, , "", 2
    Do While .Execute(Chr(27), , , , , , , 1) = True
    oWord.Selection.HomeKey , 1
    oWord.Selection.EndKey , 1
    oWord.Selection.Delete
    Loop
    .Execute "^w^p", , , , , , , 1, , "^p", 2
    Do While .Execute("^p^p^p", , , , , , , 1, , "^p", 2) = True
    Loop
    .Execute "", , , , , , , 1, , "", 2
    .Execute "Parts:, Continued", , , , , , , 1, , "", 2
    .Execute "Paint & Materials, Continued", , , , , , , 1, , "", 2

    End With
    oDoc.Content.Font.Size = 9
    ' Save and close the document
    oDoc.Protect 2, , "mfg"
    oDoc.SaveAs "C:MM-UtilitiesM&M " & strType & " " & JN & ".doc"
    oDoc.Close False
    Set oDoc = Nothing
    oWord.NormalTemplate.Saved = True
    oWord.Quit
    Set oWord = Nothing
    Unload frmWait
    End Sub
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Process WordDoc (vb6)

    Hi Dave,

    Could you attach a sample file? You can replace the name and address of the customer with dummy data, but please leave the rest intact.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Process WordDoc (vb6)

    Hans

    I've attached two which are the most popular.
    The words PROFORMA-INVOICE & INVOICE should stay on there respective documents.

    Thanks.

    Just to add, the code which selects the document type is:

    Public Sub HandleWordDoc(strType As String, mm As MAPIMessages, ms As MAPISession)
    Dim strFile As String
    Dim strType2 As String
    Dim strBody As String

    Select Case strType
    Case "CusInvoice"
    strFile = "C:CusInv.doc"
    strType2 = "Invoice"

    Case "SWInvoice"
    strFile = "C:InsInv.doc"
    strType2 = "Invoice"

    Case "SWEstimate"
    strFile = "C:Est.doc"
    strType2 = "Estimate"

    Case "SWCredit"
    strFile = "C:Credit.doc"
    strType2 = "Credit"

    End Select

    If Dir(strFile) = "" Then
    MsgBox "There Are No " & strType2 & "s To Print" & vbCrLf & _
    "You Must Print An " & strType2 & " From Shopwatch First" & vbCrLf & vbCrLf & _
    "PRINTER 24 = INSURER INVOICE" & vbCrLf & _
    "PRINTER 25 = ESTIMATE" & vbCrLf & _
    "PRINTER 26 = CUSTOMER INVOICE" & vbCrLf & _
    "PRINTER 27 = CREDIT NOTE", vbInformation, "Error"

    Exit Sub
    End If

    Dim JN As String

    JN = InputBox("Please Enter A Reference Number For Your Document", "Document Info")
    If StrPtr(JN) = 0 Then

    Else
    If Len(JN) = 0 Then
    MsgBox "Reference No. Not Supplied, Please Try Again", vbInformation, "Input Error"
    Else
    ' Process document
    ProcessWordDoc strFile, JN, strType2
    End If
    End If
    End Sub
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Process WordDoc (vb6)

    Hi Dave, the layout of the documents has indeed changed. Try this version of the code:
    <code>
    Public Sub ProcessWordDoc(strFile As String, JN As String, strType As String)
    Dim oWord As Object
    Dim oDoc As Object
    frmWait.Show
    ' Start Word
    Set oWord = CreateObject("Word.Application")
    ' Create document based on template
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesLongtonHeader.dot")
    ' Import report
    oWord.Selection.InsertFile strFile, , False
    ' Process document
    oWord.Selection.HomeKey 6
    ' Replace various stuff
    With oWord.Selection.Find
    .MatchWildcards = True
    .Execute "*" & Chr(27) & "M" & Chr(27) & "l", , , , , , , , , "", 1
    .MatchWildcards = False
    .Execute "^p^p^p^p^p^wINVOICE", , , , , , , 1, , _
    "^m INVOICE", 2
    .Execute "^p^p^p^p^p^wESTIMATE", , , , , , , 1, , _
    "^m ESTIMATE", 2
    .Execute Chr(26), , , , , , , 1, , "", 2
    Do While .Execute(Chr(27), , , , , , , 1) = True
    oWord.Selection.HomeKey , 1
    oWord.Selection.EndKey , 1
    oWord.Selection.Delete
    Loop
    .Execute "^w^p", , , , , , , 1, , "^p", 2
    Do While .Execute("^p^p^p", , , , , , , 1, , "^p", 2) = True
    Loop
    .Execute "", , , , , , , 1, , "", 2
    .Execute "Parts:, Continued", , , , , , , 1, , "", 2
    .Execute "Paint & Materials, Continued", , , , , , , 1, , "", 2
    End With
    ' Format
    oDoc.Content.Font.Size = 9
    ' Save and close the document
    oDoc.Protect 2, , "mfg"
    oDoc.SaveAs "C:MM-UtilitiesM&M " & strType & " " & JN & ".doc"
    oDoc.Close False
    Set oDoc = Nothing
    oWord.NormalTemplate.Saved = True
    oWord.Quit
    Set oWord = Nothing
    Unload frmWait
    End Sub</code>

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Process WordDoc (vb6)

    Hans

    The girls in Accounts can't thank you enough.
    We ran out of letter headed listing paper and can't get any for another two weeks.
    Every invoice is now going through the program until they can deliver, so they have been unprotecting each invoice and manually editing the header text which is taking them along time to sort.

    So from the girls, <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •