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

Macro not working properly when document opened

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


Joined: 27 Dec 2006
Posts: 3

PostPosted: Wed Dec 27, 2006 9:02 am    Post subject: Macro not working properly when document opened Reply with quote

I am having a problem with my macro. The macro does some calculations from data listed on the second sheet. When I use it in a new cell (after the doc is opened), it works fine. I saev the doc, close it and re-open it, and I am getting errors. When I do:

oDoc = ThisComponent
oSheet = oDoc,Sheets.GetByName('<name of sheet 2>')

I am getting a runtime error "com.sun.star.container.NoSuchElementException' occuring. When I change this to:

oDoc = ThisComponent
oSheet = oDoc,Sheets.GetByIndex(1)

the error no longer occurs, but the when later in the macro trhying to access the contents of a cell:

oCell = oSheet.getCellByPosition(0,I)

oCell.string seems to be empty, even though the cell in question has a string in it. It is almost as if the macro is running before the doc finishes loading. Any clue as to why this is occuring?
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Wed Dec 27, 2006 1:51 pm    Post subject: Reply with quote

For your first problem try:
oSheet = oDoc.Sheets.GetByName("name of sheet 2") instead of
oSheet = oDoc,Sheets.GetByName('<name of sheet 2>')

I presume the use of a comma after oDoc was a typo but I doubt '< and >' were.
Back to top
View user's profile Send private message
cgifford
Newbie
Newbie


Joined: 27 Dec 2006
Posts: 3

PostPosted: Thu Dec 28, 2006 4:28 am    Post subject: Yeah, they were typos Reply with quote

The quotes were typos as well, but thanks for the input!
Back to top
View user's profile Send private message
cgifford
Newbie
Newbie


Joined: 27 Dec 2006
Posts: 3

PostPosted: Thu Dec 28, 2006 4:31 am    Post subject: Just found the problem too! Reply with quote

The macro i created was under "My Macros->Standard". Moving it to the "Name of Doc->Standard" solved the problem!
Back to top
View user's profile Send private message
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