Hi

I have a form which allow the customer to send out reminders who haven't paid 
there subscription yet.
The following is the code I use to automate "Word".
The form allows printing a batch of reminders, editing a letter, Previewing a 
sample

First the code behind the Edit Letter button.
***************************************

Local lcDefault As Character, lcWordFile As Character, oleWord As Object

lcDefault = Set("Default")

Set Default To (oGlobal.cWordDocsPath)

Do Case  && Radio Buttons show 4 options but as one is not being used yet it is 
diabled.
        Case ThisForm.Optiongroup1.Value = 1 .And. ThisForm.Optiongroup2.Value 
= 1
                lcWordFile = "AnnualPayersInd2010.doc"
        Case ThisForm.Optiongroup1.Value = 2 .And. ThisForm.Optiongroup2.Value 
= 1
        Case ThisForm.Optiongroup1.Value = 3 .And. ThisForm.Optiongroup2.Value 
= 1
                lcWordFile = "AnnualPayersInd2010.doc"
        Case ThisForm.Optiongroup1.Value = 4 .And. ThisForm.Optiongroup2.Value 
= 1
                lcWordFile = "AnnualPayerReminderVariation1.doc"
        Case ThisForm.Optiongroup1.Value = 1 .And. ThisForm.Optiongroup2.Value 
= 2
                lcWordFile = "AnnualPayersJoint2010.doc"
        Case ThisForm.Optiongroup1.Value = 2 .And. ThisForm.Optiongroup2.Value 
= 2
        Case ThisForm.Optiongroup1.Value = 3 .And. ThisForm.Optiongroup2.Value 
= 2
                lcWordFile = "AnnualPayersScotlandJoint2010.doc"
        Case ThisForm.Optiongroup1.Value = 4 .And. ThisForm.Optiongroup2.Value 
= 2
                lcWordFile = "AnnualPayerReminderVariation2.doc"
EndCase

Thisform.txtSavedDocument.Value = lcWordFile

lcWordFile = Alltrim(oGlobal.cWordDocsPath) + Alltrim(lcWordFile)

oleWord = Createobject("Word.Application")

With oleWord
        .Documents.Add(lcWordFile)
        .Visible = .T.
    .ChangeFileOpenDirectory(oGlobal.cWordDocsPath) && change the documents 
title so it saves correctly
Endwith

Declare Integer BringWindowToTop In Win32API ;
        Integer HWnd

lnHand = IsRunning(" - Microsoft Word ") && Check if there is a window title 
like this.
If lnHand <> 0
        BringWindowToTop(lnHand) && Bring word to the top.
Endif

Set Default To &lcDefault

The code for the IsRunning procedure is on the link below. 
This checks to see if the word document is open and if so brings it to the 
front.
***************************************

http://www.ml-consult.co.uk/foxst-11.htm

Second is a method which is called from the Print button which scans through 
the result of a query.
Note that each letter has 4 letters i.e. AAAA to distinguish each field on the 
template document.
***************************************

Lparameters lcWordFile As Character ,llPrint As Logical

&& The Print or Preview buttons pass the name of the document to be edited and 
whether to print or not

Local lcLongDate As Character ,lcAddress As Character ,lcAddress1 As Character 
Local lcAddress2 As Character ,lcAddress3 As Character ,lcAddress4 As Character 
Local lcPostCode As Character ,lcTitle As Character ,lcFullname As Character 
Local lcRefNo As Character ,lcGroup As Character ,lcPayType As Character 
Local lcSurname As Character ,lcTitle As Character,lcCurrency As Character 

lcLongDate = LongDate(Date())  && E.g.Change to "1st of April 2011"

lcAddress1 = Proper(Alltrim(MembRenewal.Addr1)) && Pick up Address etc. from 
the result of a query
lcAddress2 = Proper(Alltrim(MembRenewal.Addr2)) && Radio buttons select what 
area of the UK and
lcAddress3 = Proper(Alltrim(MembRenewal.Addr3)) && whether Individual or Joint 
membership.
lcAddress4 = Proper(Alltrim(MembRenewal.Addr4))
lcPostCode = Alltrim(MembRenewal.Postcode)
lcFullname = Proper(Alltrim(MembRenewal.FullName))
lcSurname = " " + Proper(Alltrim(MembRenewal.Surname))
lcTitle = Proper(Alltrim(MembRenewal.Title))

If Upper(lcTitle) = "MRS"
        cSpouse = " husband"
Else
        cSpouse = " wife"
Endif

lcAddress = lcAddress1 + Chr(13) + ;
        Iif(!Empty(lcAddress2),lcAddress2 + Chr(13),"") + ;
        Iif(!Empty(lcAddress3),lcAddress3 + Chr(13),"") + ;
        Iif(!Empty(lcAddress4),lcAddress4 + Chr(13),"") + ;
        lcPostCode

oleWord = Createobject('Word.Application')

With oleWord

        If Thisform.chkShowDocument.Value = 1
                oleWord.Visible = .T.
        Endif
        .Documents.Add(oGlobal.cWordDocsPath + lcWordFile)

        Declare Integer BringWindowToTop In Win32API ;
                Integer HWnd

        lnHand = IsRunning(" - Microsoft Word ")  && Link to IsRunning code is 
http://www.ml-consult.co.uk/foxst-11.htm
        If lnHand <> 0
                BringWindowToTop(lnHand)
        Endif

        .Selection.Find.Execute('AAAA')         && Find AAAA
        .Selection.Delete                       && delete it
        .Selection.TypeText(lcLongDate)         && Insert the date

        .Selection.Find.Execute('BBBB')
        .Selection.Delete
        .Selection.TypeText(lcFullname + Chr(13) + lcAddress)

        .Selection.Find.Execute('CCCC')
        .Selection.Delete
        .Selection.TypeText(MembRenewal.RefNo)

        .Selection.Find.Execute('DDDD')
        .Selection.Delete
        .Selection.TypeText(lcTitle + lcSurname + ",")

        .Selection.Find.Execute('EEEE')
        .Selection.Delete
        .Selection.TypeText(" " + Transform(Thisform.txtYear.Value))  && Print 
just the year part of the current year.

        .Selection.Find.Execute('FFFF')
        .Selection.Delete
        .Selection.TypeText(Transform(Thisform.txtYear.Value) + " ")

        If  Thisform.optiongroup1.Value = 1 .Or. Thisform.optiongroup1.Value = 
3  && Some Letters have an extra field
                .Selection.Find.Execute('GGGG')
                .Selection.Delete
                If Thisform.optiongroup2.Value = 1
                        lcCurrency = Thisform.txtIndividualSubscription.Value
                        lcCurrency = Transform(lcCurrency,'99.99')
                        lcCurrency = "£" + lcCurrency
                        .Selection.TypeText(lcCurrency + " ")
                Else
                        lcCurrency = Thisform.txtJointSubscription.Value
                        lcCurrency = Transform(lcCurrency,'99.99')
                        lcCurrency = "£" + lcCurrency
                        .Selection.TypeText(lcCurrency + " ")
                Endif
        Endif

        .Selection.Find.Execute('HHHH')
        .Selection.Delete
        If Thisform.optiongroup2.Value = 1
                lcCurrency = Thisform.txtIndividualSubscription.Value
                lcCurrency = Transform(lcCurrency,'99.99')
                lcCurrency = "£" + lcCurrency
                .Selection.TypeText(lcCurrency + " ")
            .Selection.MoveLeft(1,7,1)
        .Selection.Font.Bold = .T.
        Else
                lcCurrency = Thisform.txtJointSubscription.Value
                lcCurrency = Transform(lcCurrency,'99.99')
                lcCurrency = "£" + lcCurrency
                .Selection.TypeText(lcCurrency + " ")
            .Selection.MoveLeft(1,7,1)
        .Selection.Font.Bold = .T.
        Endif

    .Selection.MoveDown(5,25)  && take cursor to bottom of page in case the 
press a key by accident

        If llPrint
                .ActiveDocument.PrintOut
                Wait Window "Printing reminder Letter" Timeout 20
                .Quit(.F.)
        Endif

Endwith

Could this be the sort of thing you're after.
Note that some of the automation code may need an "If Then" or a "Do case" to 
ask what version of office and change the code accordingly.
The instruction to print the document is one of these.
My Client is totally Office 2010.
Any suggestions to improve the above code will be gratefully accepted.

Cheers

Peter Hart
Peter Hart Computers
www,.peterhartcomputers.co.uk

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of 
Mike Copeland
Sent: 23 June 2011 06:05
To: [email protected]
Subject: Re: Text Editing in VFP App

What this client was doing, and what I'm looking at doing, is providing 
templates that have a basic layout, then inserting data from my application 
(prices, SKU #s, description, feature list) at print time. 
The end user can either use the template "as is" or modify the layout to their 
liking. The layout will contain placeholders for data that will be updated when 
processed/printed...a basic data merge.

So, yeah, the template document would just be opened, and saved, but then I 
need to be able to automate the mass merging from my VFP app. 
I've already got an email application that does this with HTML and it works 
great although the HTML editing is a lot more involved. I've not yet found an 
HTML editor that can be automated from VFP.



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to