VB6 : working with Word documents
Created 30 September 2002 00:00
The following shows how to programmatically open, modify, save and close a word document.
var
  oWordApp: Variant;
  oBookmark: Variant;
  oRange: Variant;
begin
  try
    oWordApp := CreateOleObject('Word.Application');
  except on E: Exception do
    begin
    ShowMessage('Word does not appear to be installed: ' + E.Message);
    Exit;
    end;
  end;
  // open the document and manipulate text
  try
    begin
    oWordApp.Visible := False;
    oWordApp.Documents.Open(FileName);
    oBookmark := WordApp.ActiveDocument.Bookmarks.Item('NamedBookark');
    oRange := oBookMark.Range;
    oRange.Select;
    oRange.Text := 'New text that you have written!';
    oRange := Unassigned;
    oBookmark := Unassigned;
    oWordApp.ActiveDocument.Save;
    end;
  except on E: Exception do
    begin
    ShowMessage('Unable to generate report: ' + E.Message);
    end;
  end;
  // close word and clean up
  oWordApp.Quit;
  oWordApp := Unassigned;
end;
Loading images from Jar Files
Created 12 September 2002 00:00
  try {
    URL url = FreeArchiver.class.getResource("/images/yourimg.gif"); 
    // the following line is necessary to be able to catch the exception if
    // the image does not exist in the resource
    url.getFile();
    Image img = Toolkit.getDefaultToolkit().getImage(url); 
    setIconImage(img);
  }
  catch (Exception e) {
    System.err.println("Unable to load image from archive.");
  }
Working with word documents in Delphi
Created 30 September 2002 00:00
The following shows how to programmatically open, modify, save and close a word document.
var
  oWordApp: Variant;
  oBookmark: Variant;
  oRange: Variant;
begin
  try
    oWordApp := CreateOleObject('Word.Application');
  except on E: Exception do
    begin
    ShowMessage('Word does not appear to be installed: ' + E.Message);
    Exit;
    end;
  end;
  // open the document and manipulate text
  try
    begin
    oWordApp.Visible := False;
    oWordApp.Documents.Open(FileName);
    oBookmark := WordApp.ActiveDocument.Bookmarks.Item('NamedBookark');
    oRange := oBookMark.Range;
    oRange.Select;
    oRange.Text := 'New text that you have written!';
    oRange := Unassigned;
    oBookmark := Unassigned;
    oWordApp.ActiveDocument.Save;
    end;
  except on E: Exception do
    begin
    ShowMessage('Unable to generate report: ' + E.Message);
    end;
  end;
  // close word and clean up
  oWordApp.Quit;
  oWordApp := Unassigned;
end;