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
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