Hi Lian,

the reason is that ThisComponent.getCurrentController returns not the
controller of the expected document. You run the macro when opening the
document and at this time the ThisComponent is probably set ot something
else. It is always a little bit tricky with ThisComponent.getCurrentXXX
methods. It's better to iterate over all frame/controllers and check if
the name is whatever.odt to ensure that you work with the right document.

Juergen

Liang Weike wrote:
> Hello all,
> 
> Recently I get a piece of Basic macro and test it in my computer. But I
> met problems when running it. The problem can be described as follows:
> 
> 1. Open a new writer document. Save it as whatever.odt.
> 2. Select Tools -> Macros -> Organize Macros -> OpenOffice.org Basic...
> from the menu to open the OpenOffice.org Basic Macros dialog.
> 3. Create whatever.odt a new module, with the following macro:
> --------------------------------------------
> REM ***** BASIC *****
> 
> Sub Main
> oFrame=thiscomponent.getcurrentcontroller.getFrame
> dim args(0) as new com.sun.star.beans.PropertyValue
> oFrame.loadComponentFromURL("private:factory/swriter", "_self",23, args)
> End Sub
> --------------------------------------------
> 5. Save whatever.odt and close it.
> 6. "Enable Macros" on reopening whatever.odt.
> 7. Reopen the module we created above in the editing window.
> 8. Run the module from the toolbar. And the application crashes, instead
> of opening a new writer document as expected.
> 
> However, if this macro is run in a "Untitled" document, or run directly
> from Tools -> Macros -> Run Macro. The result is all right.
> 
> I felt it was strange, and so could you help figure out where the source code 
> goes wrong?
> Thank you in advance. :-) 
> 
> Best regards,
> Liang Weike 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to