Closing PrintPreview mode in a macro
Posted: Sat Mar 29, 2008 12:25 pm
Hi
I have a macro that opens all the spreadhseets in a directory and copies information from them and then closes them. It works great up till the point when I get to open a spreadheet that has been save in the state of a PrintPreview. Then the macro crashes. I figured the easiest way arround this would be open the spreadhseet and then close print preview but I am strugling. I used the macro recorder to see what the code should look like and got this.
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ClosePreview", "", 0, Array())
If I put a spreadsheet in PrintPreview mode and run this macro it works perfectly. Then I needed to convert it to work with my main macro and this is the code that I have come up with (hobbled together from other coded that woks in my macro!)
oSrcDoc = StarDesktop.loadComponentFromUrl(s,"_blank",0,Array()) - where s is the name of the file to open
dim documentx as object
dim dispatcherx as object
dispatcherx = createUnoService("com.sun.star.frame.DispatchHelper")
documentx = oSrcdoc.getCurrentController().getFrame()
dispatcherx.executeDispatch(documentx, ".uno:ClosePreview", "", 0, Array())
This has no effect on the document and PrintPreview mode is not closed and the program crashes.
I "copied" this syntax from the following lines which work!
oTargetframe = oTargetDoc.getCurrentController().getFrame()
oDispatcher.executeDispatch(oTargetframe, ".uno:InsertContents", "", 0, args4())
in that case the dispatcher properly pastes the clipboard contents into my target doc
So I do not understand why the dispatcher will not operate on the oSrcdoc and close the PrintPreview
Of course my understanding of all of this is not complete and I have just kludged it together from other examples - but to me it seems as if it should work.
What have I perhaps misunderstood and implemented incorrectly
Thanks
Trev
I have a macro that opens all the spreadhseets in a directory and copies information from them and then closes them. It works great up till the point when I get to open a spreadheet that has been save in the state of a PrintPreview. Then the macro crashes. I figured the easiest way arround this would be open the spreadhseet and then close print preview but I am strugling. I used the macro recorder to see what the code should look like and got this.
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ClosePreview", "", 0, Array())
If I put a spreadsheet in PrintPreview mode and run this macro it works perfectly. Then I needed to convert it to work with my main macro and this is the code that I have come up with (hobbled together from other coded that woks in my macro!)
oSrcDoc = StarDesktop.loadComponentFromUrl(s,"_blank",0,Array()) - where s is the name of the file to open
dim documentx as object
dim dispatcherx as object
dispatcherx = createUnoService("com.sun.star.frame.DispatchHelper")
documentx = oSrcdoc.getCurrentController().getFrame()
dispatcherx.executeDispatch(documentx, ".uno:ClosePreview", "", 0, Array())
This has no effect on the document and PrintPreview mode is not closed and the program crashes.
I "copied" this syntax from the following lines which work!
oTargetframe = oTargetDoc.getCurrentController().getFrame()
oDispatcher.executeDispatch(oTargetframe, ".uno:InsertContents", "", 0, args4())
in that case the dispatcher properly pastes the clipboard contents into my target doc
So I do not understand why the dispatcher will not operate on the oSrcdoc and close the PrintPreview
Of course my understanding of all of this is not complete and I have just kludged it together from other examples - but to me it seems as if it should work.
What have I perhaps misunderstood and implemented incorrectly
Thanks
Trev