Error message while trying to activate code from button

Creating a macro - Writing a Script - Using the API

Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 11:00 am

I have this code

Code: Select all   Expand viewCollapse view
Sub exportpdf( cFile )
   cURL = ConvertToURL( cFile )
   ' Open the document. Just blindly assume that the document
   ' is of a type that OOo will correctly recognize and open
   ' without specifying an import filter.
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
            Array(MakePropertyValue( "Hidden", True ),))

   cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
   cURL = ConvertToURL( cFile )
   
   ' Save the document using a filter.   
   oDoc.storeToURL( cURL, Array(_
            MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
   
   oDoc.close( True )
End Sub


...And it is bind to a button in my spreadsheet document and when i press the button it gives this error:

"A Scripting Framework error occured while running the Basic script ynd.sun.star.script:Standard.Module1.Example?Language=Basic&location=application

Message: BasicProviderlmpl::getScript: no script!"

I dont feel like that the code would be the source of problem but i still dont know where it comes from...
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby DrewJensen » Fri Mar 14, 2008 1:21 pm

This sounds like a known problem that has been fixed in the new version coming out. To be sure - if you close the file and reopen it again ( with OOo still in memory ) and the macro then works, that's it.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 1:30 pm

DrewJensen wrote:To be sure - if you close the file and reopen it again ( with OOo still in memory ) and the macro then works, that's it.


Didn't work for me (i closed the document {with the OO still being open] and opened it again) ...Well, maybe i'll just wait for the new version and while that bang my head into wall and try other forms of codes. Thanks anyway.
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby DrewJensen » Fri Mar 14, 2008 1:50 pm

hmmm.. and if you just click the button a second time does it work?
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 2:01 pm

No, it just gives the same error again and again, no matter how many times i press it even though i would have closed the document and reopened it, it just keeps repeating the error :cry:
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby DrewJensen » Fri Mar 14, 2008 2:04 pm

Where do you have the actual code - stored in the document or stored in a separate library. If it where me the first I would try is to reverse which ever you have now and see if that 'kicks it in the rear and wakes it up'..
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 2:17 pm

Tools-->Macros-->Organize Macros-->OpenOffice.org Basic...-->My Macros-->Standard-->Module1

There is a macro named "exportpdf" and that is where my code remains, where should i put it to (hopefully) get it work?
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby hol.sten » Fri Mar 14, 2008 2:36 pm

Otapi wrote:I have this code
Code: Select all   Expand viewCollapse view
            MakePropertyValue( "FilterName", "writer_pdf_Export" ),)

...And it is bind to a button in my spreadsheet document and when i press the button it gives this error:

"A Scripting Framework error occured while running the Basic script ynd.sun.star.script:Standard.Module1.Example?Language=Basic&location=application

Message: BasicProviderlmpl::getScript: no script!"

I dont feel like that the code would be the source of problem but i still dont know where it comes from...

You use the filter name writer_pdf_Export and call this macro from a spreadsheet aka OOo Calc. What type of document are you using as parameter cFile? Where do you get it from?
Last edited by hol.sten on Fri Mar 14, 2008 2:40 pm, edited 1 time in total.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: Error message while trying to activate code from button

Postby DrewJensen » Fri Mar 14, 2008 2:39 pm

LOL - ah reading the code...now that is a novel idea...kind of a rotten error message however.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Error message while trying to activate code from button

Postby hol.sten » Fri Mar 14, 2008 2:43 pm

DrewJensen wrote:LOL - ah reading the code...now that is a novel idea

Most people provide it for reading, I thought.

DrewJensen wrote:kind of a rotten error message however.

And a widely used error message. OOo uses it a lot, unfortunately.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: Error message while trying to activate code from button

Postby DrewJensen » Fri Mar 14, 2008 2:45 pm

Sometimes timing is everything - I've been running down the "Verified Fixed" Issues for Base over the last few days trying to test them and close them against the 2.4 RC builds and two of them had to do with the fact that the "Script not found" error happens when embedded forms are loaded the first time...the mind just went right along with this as another manifestation of the same bug.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 2:48 pm

i thought it would be something about the file name because in the error it gave phrase "Standard.Module1.Example" which is actually the source of the macro (though i dont know where the "example" in there comes because my macro was named before as "example" but recently i changed it, can't understand why its whining about that)
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby hol.sten » Fri Mar 14, 2008 3:41 pm

Otapi wrote:i thought it would be something about the file name because in the error it gave phrase "Standard.Module1.Example" which is actually the source of the macro (though i dont know where the "example" in there comes because my macro was named before as "example" but recently i changed it, can't understand why its whining about that)

So the problem still exists? Did you rename the macro before or after you assigned it to the spreadsheet button? What is the name of the macro in the button? How do you assign the file name at the button? Why are you converting an arbitrary file in a spreadsheet at all instead of converting the current spreadsheet?
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: Error message while trying to activate code from button

Postby Otapi » Fri Mar 14, 2008 3:45 pm

Well, currently i cant get my hands on the document since the bloody file wont open (i guess its my computer that is heating, stupid old Compaq Presario that has been on all day and it's getting slower and slower)

...also im at work now so we propably need to return to this subject after weekend :E
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am

Re: Error message while trying to activate code from button

Postby hol.sten » Sat Mar 15, 2008 5:09 pm

This is curious. I rewrote the OOo Basic code from above for a little test:
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

Sub Main

  exportpdf("c:\temp\TestWriter.odt", "WriterPDF")
  exportpdf("c:\temp\TestWord.doc", "WriterPDF")
  exportpdf("c:\temp\TestImpress.odp", "WriterPDF")
  exportpdf("c:\temp\TestPowerpoint.pps", "WriterPDF")
  exportpdf("c:\temp\TestCalc.ods", "WriterPDF")
  exportpdf("c:\temp\TestExcel.xls", "WriterPDF")

  rem exportpdf("c:\temp\TestWriter.odt", "CalcPDF")
  rem exportpdf("c:\temp\TestWord.doc", "CalcPDF")
  exportpdf("c:\temp\TestImpress.odp", "CalcPDF")
  exportpdf("c:\temp\TestPowerpoint.pps", "CalcPDF")
  exportpdf("c:\temp\TestCalc.ods", "CalcPDF")
  exportpdf("c:\temp\TestExcel.xls", "CalcPDF")

End Sub

Sub exportPdf(cFile as string, cPdfType as string)

  cURL = ConvertToURL(cFile)
  oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True),))

  cFilename = Left(cFile, Len(cFile) - 4) + cPdfType + ".pdf"
  cPdfURL = convertToURL(cFilename)

  if (cPdfType = "CalcPDF") then
    oDoc.storeToURL(cPdfURL, Array(MakePropertyValue( "FilterName", "calc_pdf_Export" ),)
  elseif (cPdfType = "WriterPDF") then
    oDoc.storeToURL(cPdfURL, Array(MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
  end if 

  oDoc.close(True)

End Sub

As you can see, I have 6 documents in different file formats: TestWriter.odt, TestWord.doc, TestImpress.odp, TestPowerpoint.pps, TestCalc.ods, and TestExcel.xls.

To execute the code without any errors, all I had to do was to comment the document conversion of TestWriter.odt and TestWord.doc with the PDF export filter "calc_pdf_Export".

Why does the export filter "writer_pdf_Export" convert Calc and Impress file formats? Why does the export filter "calc_pdf_Export" convert Impress file formats? Can anyone reproduce this behavior?
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: Error message while trying to activate code from button

Postby Otapi » Mon Mar 17, 2008 11:21 am

Now i know what is the problem (though i still dont know how to solve it)

The macro in button is:

vnd.sun.star.script:Standard.Module1.Example?language=Basic&location=application

so it is the "Example" in "Module1", though the problem still is that when i try to remove the current macro and set new on the button it wont remove the "Example" macro, nor set the macro but instead it just keeps the "Example" macro there (which does not exist anymore and because of that, has no script on it)

How can i put a new macro on the button so that the old will be removed and new one will go there?

EDIT: Problem solved but now there is a new problem. When i press the button where the macro is it just opens the form where code is and darkens the "cURL = ConvertToURL( cFile )" part.
Otapi
 
Posts: 13
Joined: Thu Mar 13, 2008 10:43 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests