OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Copy Sheet using Macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Juri
Guest





PostPosted: Mon Mar 22, 2004 5:57 am    Post subject: Copy Sheet using Macro Reply with quote

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
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Mar 22, 2004 7:21 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Mar 22, 2004 9:05 am    Post subject: Reply with quote

I'm just posting a cross reference to this...

http://www.oooforum.org/forum/viewtopic.php?t=7026
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Mar 23, 2004 7:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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