Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oleobject - word

Status
Not open for further replies.

tinac99

Programmer
Jan 17, 2002
58
US
Hi,

I'm trying to do a find and replace using the oleobject connected to a word document. Code is written below and it is crashing. Any leads, answers and solutions will be greatly appreciated.

Thanks,

Tina
--------------------------------------------------
oleobject ole_object1
oleobject ole_wordfind
integer result, li_rc
string ls_file = "C:\No detainer letter.doc"
string ls_null

setnull(ls_null)
ole_object1 = CREATE OLEObject

result = ole_object1.ConnectToNewObject("word.application")

ole_object1.Documents.open("C:\Derived.doc")

ole_object1.Selection.Find.Forward=True
ole_object1.Selection.ClearFormatting
ole_wordfind = ole_object1.Selection.Find
result = ole_wordfind.Execute("<letter_date_literal>",0,0,0,0,0,1,1,ls_null,"July 1, 2007","July 1, 2007",0,0,0,0)
ole_object1.activedocument.saveas("C:\Derived.doc")


Thanks,

Tina
 
hello Tina,
Can u plz tell me which version u use of PB.
I have that code and i have error occur on oleobject.insert (laddress)
i m new in this site.
Plz advice how it is solve.
thanks
Sonu

Any lResult
Long lTotRows,i,j,ret
String lAddress
// Declare and create ole object.
OLEObject OLEMailMerge
OLEMailMerge = CREATE OLEObject
lResult = OLEMailMerge.ConnectToNewObject( "word.basic" )
If Integer(lResult) <> 0 Then
DESTROY OLEMailMerge
MessageBox( "Error in connecting to Word for Windows", "Error Code: " + String( lResult ) )
Return
End If
lTotRows = dw_1.Rowcount()
For i = 1 to lTotRows Step 1
lAddress = dw_1.GetItemString(i,1)
// For j = 2 to 7 Step 1
// lAddress = lAddress + "~r~n" + &
// dw_1.GetItemString(i,j)
// Next
Messagebox("add",lAddress)
ClipBoard( lAddress )
lResult = OLEMailMerge.FileOpen("C:\doc\ole_letter.doc")
If Integer(lResult) <> 0 Then
DESTROY OLEMailMerge
MessageBox("Error in connecting to Word " + &
"for Windows", "Error Code: " + String( lResult ) )
Return
End If
Messagebox("lResult",string(lResult))
// These are the important commands:
OLEMailMerge.editgoto( "Address" )
ret = OLEMailMerge.Selection.typetext( lAddress )
Messagebox("Ret",string(ret))
OLEMailMerge.FilePrint()
OLEMailMerge.FileClose( 2 )
Next
lResult = OLEMailMerge.DisConnectObject()
DESTROY OLEMailMerge
 
Try to use the mail merge
iRet = objWordDoc.ConnectToNewObject("Word.Application")
IF iRet = 0 THEN
objWordDoc.Documents.Open("filename.doc")
objWordDoc.ActiveDocument.MailMerge.OpenDatasource("datafile.cvs")
objWordDoc.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
objWordDoc.ActiveDocument.MailMerge.Destination = 0 //Merge to File
objWordDoc.ActiveDocument.MailMerge.Execute(True)//Execute merge

objWordDoc.ActiveDocument.PrintOut(FALSE)
objWordDoc.ActiveDocument.SaveAs("filename.doc")
objWordDoc.ActiveDocument.Close(0)
objWordDoc.ActiveDocument.Close(0)//Close merge doc
objWordDoc.Application.quit()
objWordDoc.DisconnectObject()
END IF
DESTROY objWordDoc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top