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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass variable to MS Word

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have the following Delphi code that opens a Microsoft Word Document. I have two variables (strVenire and strFormat) that need to be passed to the VBA function in my word document. How can I call the Word function from Delphi and pass the two variables?? Thanks for any assistance. Leslie

procedure TdlgVenireRequest.FormActivate(Sender: TObject);
var
strVenire, strFormat: string;
strFileName: String;
Word: Variant;

begin
qryVenireReq.Active := True;
strVenire := qryVenireReq.fieldbyname('APPDAT').asstring;
strFormat := copy(strVenire, 5, 2) + '/' + copy(strVenire, 7, 2) + '/' + copy(strVenire, 1, 4);
strFileName := 'C:\Request.doc';
Word := CreateOleObject('Word.Application');
Word.Visible := True;
Word.Documents.Open(FileName:= strFileName, ReadOnly:=False);
{Call Word sub UpdateText here!}
Sleep(1500);
Word.Quit;
qryRequestUpdate.ParamByName('APPDAT').AsString := strVenire;
qryRequestUpdate.ExecSQL;
end;

Sub UpDateText(venire As String, mail As String)

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "date"
.Replacement.Text = venire
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "YYYYMMDD"
.Replacement.Text = mail
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'ActiveDocument.PrintOut
'ActiveDocument.Close (wdDoNotSaveChanges)
End Sub
 
For anyone interested, I figured this out. By placing the Word procedure in This Document - rather than in the Modules, you can call the procedure with:

Word := CreateOleObject('Word.Application');
Word.Visible := True;
wrdDoc := Word.Documents.Open(FileName:= strFileName, ReadOnly:=False);
wrdDoc.ProcedureName(parameters);
wrdDoc.Printout;
wrdDoc.close(0); ' This command causes the document to close without prompting for saves!
Word.Quit;

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top