| View previous topic :: View next topic |
| Author |
Message |
cgifford Newbie

Joined: 27 Dec 2006 Posts: 3
|
Posted: Wed Dec 27, 2006 9:02 am Post subject: Macro not working properly when document opened |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Wed Dec 27, 2006 1:51 pm Post subject: |
|
|
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 |
|
 |
cgifford Newbie

Joined: 27 Dec 2006 Posts: 3
|
Posted: Thu Dec 28, 2006 4:28 am Post subject: Yeah, they were typos |
|
|
| The quotes were typos as well, but thanks for the input! |
|
| Back to top |
|
 |
cgifford Newbie

Joined: 27 Dec 2006 Posts: 3
|
Posted: Thu Dec 28, 2006 4:31 am Post subject: Just found the problem too! |
|
|
| The macro i created was under "My Macros->Standard". Moving it to the "Name of Doc->Standard" solved the problem! |
|
| Back to top |
|
 |
|