Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word 97 Problem in VFP 5
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00123352
Message ID:
00128526
Views:
20
>Patric,
>
>Here's your code trimmed down a little. This should also run faster.
>
>** CODE BEGINS HERE **
>
>** Set up Constants
>#DEFINE CRLF CHR(13)+CHR(10)
>#DEFINE PUNCT ","
>* Declare the variable local so it doesn;t interfere with any other thing that
>* may use oWord for a variable
>LOCAL oWord, lnFirstRec
>** Create an Instance of Word
>oWord=CREATE('Word.Application')
>
>** Open a Blank Document named 'NewDoc' (This insures I am using a ** blank document)
>oWord.Documents.Open('C:\DOCS\NewDoc.Doc')
>
>** Open the department reference table
>SELECT DeptRef
>
>** Determine the number of records
>*nNumRecs=RECCOUNT()
>* Don't beed the above RECCOUNT(), see the scan loop to find out why
>** Reset pointer to top of file
>LOCATE && this is faster than GO TOP
>lnFirstRec = RECNO()
>
>** Scan through each record. If it is the last record in the table,
>** end with a hard CR, otherwise place a comma after each record
>SCAN
> oWord.Selection.insertafter(IIF(RECNO()<>lnFirstRec,PUNCT,"")+alltrim(desc))
>ENDSCAN
>oWord.Selection.insertafter(CRLF)
>
>** Save the document to 'NewDoc2'. If NewDoc2 exists, it is
>** overwritten. NOTE: The path MUST be specified or the doc will
>** be saved in C:\MYDOCUMENTS directory
>oWord.Documents('C:\DOCS\NewDoc.Doc').SaveAs('C:\DOCS\NewDoc2.Doc')
>
>** Close the instance of Word
>oWord.Quit
>
>** Close and release the form
>THISFORM.RELEASE
>
>** END CODE **
>
>The only thing I think may have given you trouble before is deleted records. They could cause reccount to not be equal to the last record number you process.

Jim,

I'm trying to do something similar. Open a .doc and save as text... but I keep getting "Unknown name" on the SaveAs line... Any idea what I'm doing wrong?

Here's the code (along with some commented out attempts). Also, how can I specify 'save as text' using this construct?

TIA

Larry

*** BEGIN CODE
oWord = GETOBJECT('','Word.Basic')

ADIR(aFileList,"*.doc")
FOR i = 1 TO 1 && ALEN( aFileList , 1 )
    cFileName = aFileList[ i, 1 ]
    cDocName = UPPER( "c:\temp\sslist\" + cFileName)
    cTxtName  = 'c:\temp\' + STRTRAN( cFileName, '.DOC', '.TXT' )

    WAIT WINDOW 'Opening...' NOWAIT NOCLEAR
    oWord.fileopen(cDocName)

    WAIT WINDOW 'Saving...' NOWAIT NOCLEAR
    oWord.Documents(cDocName).SaveAs(cTxtName)

    *!*	       ChangeFileOpenDirectory _
    *!*	        "\\fatman\users\Government Affairs\web\Develop\Programs\Shirley's Agency List\"
    *!*	    ActiveDocument.SaveAs FileName:="AFAN.txt", FileFormat:=wdFormatDOSText, _
    *!*	        LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    *!*	        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    *!*	        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    *!*	        False
    *!*	End Sub

    WAIT CLEAR
NEXT
oWord.QUIT
*** END CODE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform