| View previous topic :: View next topic |
| Author |
Message |
Juri Guest
|
Posted: Mon Mar 22, 2004 5:57 am Post subject: Copy Sheet using Macro |
|
|
Hi
How copy Sheet using Macro?
By the hands this work as
Select Sheet -> Click right button ->Copy/Move Sheet -> Select new document -> Copy
How to do this by Macro?
Thanks |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Mon Mar 22, 2004 7:21 am Post subject: |
|
|
The easiest method is to use the dispatcher
| Code: | sub MoveSheet
Dim oFrame
Dim oDispatcher
REM This will copy FROM ThisComponent
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Dim args(2) as new com.sun.star.beans.PropertyValue
args(0).Name = "DocName"
args(0).Value = "Untitled2" 'This copies to THIS document
args(1).Name = "Index"
args(1).Value = 1
args(2).Name = "Copy"
args(2).Value = False 'Set to True to perform a copy rather than a move
oDispatcher.executeDispatch(oFrame, ".uno:Move", "", 0, args())
End Sub |
I hope that this gets you started.... _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Mar 23, 2004 7:27 pm Post subject: |
|
|
Based on your personal reply to me, I see that you require a more complete example. This example is missing one thing. I create the new document, but I do not set the correct target name in the properties. I do not have time to lookup how to do this. Hopefully some other kind soul on the group will provide the code to extract the target document name from this newly created document. It is simple, but I forget how to do it off hand.
| Code: | Sub Main
Dim sNewURL$ 'URL For a NEW calc document "private:factory/scalc"
Dim oNewDoc 'New Document
Dim oFrame 'Frame that can perform the dispatch
Dim oDispatcher 'The dispatcher to use
Dim oSheet 'The current active sheet
Dim i% 'General Index Variable
Dim iActive% 'Currently active sheet
REM This will copy FROM ThisComponent
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oSheet = ThisComponent.CurrentController.getActiveSheet()
iActive = -1 : i = 0
Do While iActive < 0
If ThisComponent.Sheets(i).Name = oSheet.Name Then
iActive = i
Else
i = i + 1
End If
Loop
sNewURL = "private:factory/scalc"
oNewDoc = StarDesktop.loadComponentFromURL(sNewURL, "_blank", 0, Array())
Dim args(2) as new com.sun.star.beans.PropertyValue
args(0).Name = "DocName"
args(0).Value = "Untitled1" 'This copies to the document named Untitled1
args(1).Name = "Index"
args(1).Value = iActive
args(2).Name = "Copy"
args(2).Value = True 'Set to Flase to perform a Move
oDispatcher.executeDispatch(oFrame, ".uno:Move", "", 0, args())
End Sub |
_________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|