[Solved] Macro fails on reload of spreadsheet
[Solved] Macro fails on reload of spreadsheet
I ported a VBA macro from Excel, got it to work, and saved the spreadsheet as an OpenOffice ODS file. When I re-opened the spreadsheet, the macro gave this error:
BASIC runtime error
Sub-procedure or function procedure not defined.
on this line:
vps = Range("f6")
I see nothing wrong with the line. Here is the weird thing: If I insert a <CarrigeReturn> before the line, and then remove it, the macro runs correctly with no problem. However, if I save the spreadsheed, and re-load it, the macro fails again. If I repeat the insert and remove of the <CarriageReturn> (or any other character), the macro works again.
What could cause this weird problem? How can I get the macro to work?
BASIC runtime error
Sub-procedure or function procedure not defined.
on this line:
vps = Range("f6")
I see nothing wrong with the line. Here is the weird thing: If I insert a <CarrigeReturn> before the line, and then remove it, the macro runs correctly with no problem. However, if I save the spreadsheed, and re-load it, the macro fails again. If I repeat the insert and remove of the <CarriageReturn> (or any other character), the macro works again.
What could cause this weird problem? How can I get the macro to work?
Last edited by Hagar Delest on Mon Apr 21, 2014 7:36 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice v 4.0.1
Microsoft Windows 7 Pro, SP1
Microsoft Windows 7 Pro, SP1
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro fails on reload of spreadsheet
Are you trying to use some VBA compatibilty mode? Range() is not an OO Object, In OO Basic it would look something likeremmons wrote: vps = Range("f6")
Code: Select all
Sheet.getCellRangeByName("f6")
Code: Select all
Sheet = ThisComponent.getSheets().getByName("Sheet1")
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro fails on reload of spreadsheet
Thanks for the info. No as far as I know I am not using any compatibility mode.
I just loaded the Excel spreadsheet into Calc, and it REMed out all my macros. I just removed the REMs, expecting to debug any statements that did not work. To my surprise, I hardly had to change anything, and the code worked. Range("cell") may not be a Calc object, but I use it all over the place in Excel, and Calc seems to understand it with no problem. The macro does a fairly complicated Newton-Raphson cut and try loop to calculate a rate of return on investment, and gets the same answer as I got in Excel.
Maybe I'll try changing all the Range("cell") statements as you suggested.
I just loaded the Excel spreadsheet into Calc, and it REMed out all my macros. I just removed the REMs, expecting to debug any statements that did not work. To my surprise, I hardly had to change anything, and the code worked. Range("cell") may not be a Calc object, but I use it all over the place in Excel, and Calc seems to understand it with no problem. The macro does a fairly complicated Newton-Raphson cut and try loop to calculate a rate of return on investment, and gets the same answer as I got in Excel.
Maybe I'll try changing all the Range("cell") statements as you suggested.
OpenOffice v 4.0.1
Microsoft Windows 7 Pro, SP1
Microsoft Windows 7 Pro, SP1
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro fails on reload of spreadsheet
remmons wrote:When I re-opened the spreadsheet, the macro gave this error:
BASIC runtime error
Sub-procedure or function procedure not defined.
on this line:
vps = Range("f6")
This would seem to be a contradiction.remmons wrote:Range("cell") may not be a Calc object, but I use it all over the place in Excel, and Calc seems to understand it with no problem. The macro does a fairly complicated Newton-Raphson cut and try loop to calculate a rate of return on investment, and gets the same answer as I got in Excel.
Without seeing more of your code, it is difficult to diagnose, so I can only guess why part of it works. In a mathematical calculation like Newton-Raphson, the formulation of the mathematical expressions and the loop structures should be identical in Excel and Calc.
We've dealt with Newton-Raphson calculations in this forum before, and I have my old numerical analysis textbook close by the computer.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro fails on reload of spreadsheet
It is not that *part* of it works. All the code works sometimes. But, when I first load the sheet, it crashes. I edit the code by putting in a <CarriageReturn> and then deleting it. Then, all the code works again although there has been no actual change to the code. The act of editing the code causes it to re-compile or something behind the scenes, and that causes it to work.
I was hoping that get lucky, and the code would just work or require minimal troubleshooting. Apparently, that is not the case.
At this point, I plan to remove all the code, and put it back in line by line to isolate whatever is causing this weird problem. It is really very few lines of code anyhow.
I was hoping that get lucky, and the code would just work or require minimal troubleshooting. Apparently, that is not the case.
At this point, I plan to remove all the code, and put it back in line by line to isolate whatever is causing this weird problem. It is really very few lines of code anyhow.
OpenOffice v 4.0.1
Microsoft Windows 7 Pro, SP1
Microsoft Windows 7 Pro, SP1
Re: Macro fails on reload of spreadsheet
In a way it does require minimal troubleshooting.. you have to add, then remove, a <CarriageReturn> .. to my mind, that is minimal... the part that isn't, is the fact that you have to do it everytime you open your sheet.. which, if you open it frequently, would be a pain in more places than one.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro fails on reload of spreadsheet
How does it go if you add this to the top of your Basic module (in the .ods, before any executable code)?
Edit:
I have managed to reproduce the weird behavior with a simple case. In Excel, I created a file (.xls) containing the sub
Then opened the .xls in Calc, removed the Rems, and the macro worked. I then saved as .ods, reopened it, and yes, it behaved as described, right down to the insert/delete of a carriage return.
Now, I also find that the Option VBASupport 1 fixes the problem. It would seem that Calc, on editing the module, detects the Range(), and automatically goes into the VBASupport mode, but that's just a guess. I don't know how thorough the VBASupport is, that is how much beyond just interpreting Range() it can handle.
I would, in any case, try to translate the macro into the OpenOffice API if I were going to use it in Calc regularly. If, as you say, it isn't that long, it shouldn't be that hard to do, especially if most of the VBA specific stuff is not much more than a few Range() things. Note that the use of Range(Cell) here refers to the active sheet, and in AOO, thats
So, as I mentioned above, you could do (I prefer using methods to properties generally)
Code: Select all
Option VBASupport 1
I have managed to reproduce the weird behavior with a simple case. In Excel, I created a file (.xls) containing the sub
Code: Select all
Sub RangeBlurt()
MsgBox (Range("A1").Value)
End Sub
Now, I also find that the Option VBASupport 1 fixes the problem. It would seem that Calc, on editing the module, detects the Range(), and automatically goes into the VBASupport mode, but that's just a guess. I don't know how thorough the VBASupport is, that is how much beyond just interpreting Range() it can handle.
I would, in any case, try to translate the macro into the OpenOffice API if I were going to use it in Calc regularly. If, as you say, it isn't that long, it shouldn't be that hard to do, especially if most of the VBA specific stuff is not much more than a few Range() things. Note that the use of Range(Cell) here refers to the active sheet, and in AOO, thats
Code: Select all
ThisComponent.CurrentController.ActiveSheet
Code: Select all
ThisComponent.getCurrentController().getActiveSheet().getCellRangeByName(cellname)
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro fails on reload of spreadsheet
Thanks for the help. I added the
Option VBASupport 1
and it seems to have fixed the problem.
As far as using Calc regularly, that is what I am investigating. I am getting tired of paying Microsoft prices, and getting locked into their proprietary OS and Office Suite.
Option VBASupport 1
and it seems to have fixed the problem.
As far as using Calc regularly, that is what I am investigating. I am getting tired of paying Microsoft prices, and getting locked into their proprietary OS and Office Suite.
OpenOffice v 4.0.1
Microsoft Windows 7 Pro, SP1
Microsoft Windows 7 Pro, SP1