We help IT Professionals succeed at work.

Add object Field

Michael Sterling
on
346 Views
Last Modified: 2013-11-05
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.
Comment
Watch Question

Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Michael SterlingWeb Applications Developer

Author

Commented:
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?
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

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

ziolko.
Michael SterlingWeb Applications Developer

Author

Commented:
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.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
>>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.
Michael SterlingWeb Applications Developer

Author

Commented:
sounds good thanks for your help. get some sleep...
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Michael SterlingWeb Applications Developer

Author

Commented:
ok...sounds good. is there anyway to catch when a document is being edited? something like OnDocumentEdit similar?
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
word.application COM server has DocumentChange event, do you want to use from OleCaontainer?.

ziolko.
Michael SterlingWeb Applications Developer

Author

Commented:
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.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
it's not single-line solution, some code has to be written i'll try to find some time over weekend

ziolko.
Michael SterlingWeb Applications Developer

Author

Commented:
ok thank you. your time and effort are appreciated.
software developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
...you'll need

uses WordXP, OleServer, ActiveX;

ziolko.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Michael SterlingWeb Applications Developer

Author

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.