Link to home
Start Free TrialLog in
Avatar of Michael Sterling
Michael SterlingFlag for United States of America

asked on

Add object Field

in D7 using a TWPRichText component there is a line of code that will allow you to insert an 'OBJECT' type into the current list of fields in the document you are working with:

Editor.InputField('*', 'Subreport', 'OBJECT'); for example, (yes i'm trying to add document b to document a).

is there an equivalent line of code when using TWordApplication and TWordDocument on an OLEContainer.
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

is this what you're looking for?

uses ComObj, WordXP;

procedure TForm1.Button1Click(Sender: TObject);
var wrdApp, wrdDoc: Variant;
begin
  wrdApp := CreateOleObject('Word.Application');
  wrdApp.Visible := True;
  wrdDoc := wrdApp.Documents.Add();
  wrdDoc.Select;
  wrdDoc.ActiveWindow.View.type := wdMasterView;
  wrdDoc.Subdocuments.AddFromFile('C:\test.doc');
end;

ziolko.
Avatar of Michael Sterling

ASKER

i believe that it is. is there a way to choose the exact location within the main document where i want to open (place) the subdocument?
first of all you can change wrdApp to OleConatiner.OleObject in previuos sample.

exact position... i guess it's cursor position but i'll check it

ziolko.
yup subdocument is inserted at cursor position but you have to remove wrdDoc.Select;

ziolko.
ok when you say above: "...you can change..." are you saying that i have to or that it is an option. i haven't tried it yet just curious. and yes please if you find any source of info on how to manipulate or insert at the point of or even set the position of the cursor, please point me in that direction.
>>ok when you say above: "...you can change..."

in my sample i open word by calling CreateOleObject not via OleContainer but OleContainer.OleObject is equivalent to wrdApp in my sample.

so:
wrdDoc := wrdApp.Documents.Add() = OleContainer.OleObject.Documents.Add()

>>if you find any source of info on how to manipulate or insert at the point of or even set the position of the cursor, please point me in that direction

sure but not today :) it's midnight and that means that in 6 hours i've got to be at work:)

ziolko.
sounds good thanks for your help. get some sleep...
you can try with one of these:

OleContainer.OleObject.Selection.Move()
OleContainer.OleObject.Selection.MoveStart()
OleContainer.OleObject.Selection.MoveEnd()
OleContainer.OleObject.Selection.MoveLeft()
OleContainer.OleObject.Selection.MoveRight()
OleContainer.OleObject.Selection.MoveUp()
OleContainer.OleObject.Selection.MoveDown()

sample move up 3 lines:
OleContainer.OleObject.Selection.MoveUp(wdLine, 3);

ziolko.
ok...sounds good. is there anyway to catch when a document is being edited? something like OnDocumentEdit similar?
word.application COM server has DocumentChange event, do you want to use from OleCaontainer?.

ziolko.
yes that's exactly where i want to use it from. inside an OLEContainer is where my wordApp / wordDoc is sitting so that would be perfect.
it's not single-line solution, some code has to be written i'll try to find some time over weekend

ziolko.
ok thank you. your time and effort are appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...you'll need

uses WordXP, OleServer, ActiveX;

ziolko.
why delete?? original Q was about inserting sub-document I provided suggestion which was intially accepted {http:#19703736} then was follow-up question about moving cursor within word doc again initially accepted {http:#19710746} then was second follow-up question and once again i provided suggestion {http:#19728432} last suggestion is not solving problem, that's true, but it's second follow-up and now delete request? without even a single word why? i don't get it

ziolko.
i was able to solve my problem using a combination of some of ziolko's suggestions and my own exploration / discoveries. so i will ask that it be closed indicating this.