Page 1 of 1

[Solved] Help with macros

Posted: Wed Aug 19, 2015 8:03 pm
by MATT.B
I have attached an example of what i am working on.
im having a few issues with the macros, they are normally attached to open office not the document so no matter what doc is opened the macro is ran if i can find a solution to issue 1 i dont need solutions to the other 2 issues.
issue 1. macro errors are my biggest problem. what i want to do has the macro exit sub on errors so that when there is an error it wont display my code to the user.
issue 2. I want the startup macro to only open when the document is first loaded but if i attach it to event documentloadfinished oo waits for the macro to finish before creating the view causing the macro to return an error message, if i attach it to event documentopen it doesnt load the macro at all, if i attach it to viewcreated it crashes oo when trying to go into page/print preview, so i attached it to documentactivate but it loads the macro each time the document comes back into active view. so i changed the macro around to compensate for this error, but i would like it to load each time the document is loaded instead of only the first time.
issue 3. if a doc is saved in page preview or print preview or pagebreak preview it opens up in that view causing the macros to return errors and display my macro. im working with not so smart people that freekout when this happends, i have added a check system to check doc type before loading i would also like it to check for correct view or change it to correct view but i have yet to create a macro that will close the page preview(not pagebreak preview) so the macro may read the required cells on startup.

the macros are stored on oo and not the doc because the doc is sometimes sent to another computer and when this happends macros are disabled or have errors so i have configured each computer with macros in oo that respond to the documents that are loaded.

Re: HELP WITH MACROS

Posted: Thu Aug 20, 2015 2:20 pm
by karolus
Hallo
the macros are stored on oo and not the doc because the doc is sometimes sent to another computer and when this happends macros are disabled or have errors so i have configured each computer with macros in oo that respond to the documents that are loaded.
Bullshit - that Stuff refers to exactly this doc - so store the macros into the doc.

Re: HELP WITH MACROS

Posted: Tue Aug 25, 2015 5:44 pm
by MATT.B
Cant store macros with the document some computers are running excell and some oo the ones running oo have oo macros in oo and the ones running excel have excel macros where the macro is stored does not effect the answers to my question each computer is configured with diferent user names and macro signing doesnt transfer from computer to computer that and the doc is a template and i dont want the macros saved to the finished copy. it is set up so depending on what sheet is opened it will auto save on oo exit with out prompting the user for file destination or file name so if they forget to save it will save for them in a folder that is shared on the network but each computer is configured differently so the destination for the file is always different. on each computer i have configure this macro with slight changes to prevent errors and such also i have created 6 different documents that use this macro depending on what number is located in zz1-zz3 (for instance if zz1-3= 5555 it disables the path and filename and just saves on exit, it also prints sheet 1 page 1 and 2, sheet 2 page 1 and sheet 3 sets pagebrakes at certain points and prints all pages. if zz1-3 = 5615 it sets mypath/myfilename to a folder on the computer opening the doc saves and exports pdf version (still working on bugs for pdf export)if zz1-3 = 5616 it saves on close and sends it to an e-mail. i havent included the other codes no need the code im having isses with is when checking zz1-3 on calc documents if the view was saved other than normal view.

Re: HELP WITH MACROS

Posted: Tue Aug 25, 2015 7:57 pm
by MATT.B
I have mistaken they are not stored in openoffice macros but in my macros in openoffice

Re: HELP WITH MACROS

Posted: Wed Aug 26, 2015 10:38 pm
by MTP
For the loading: If you were only working in Calc, I would say to create a form inside your Calc document and attach the macro to the form's "When loading" event. (To create a form, open the form navigator, right-click on the work "Forms" and choose New->Form; to open the form navigator, press the sixth icon from the left or top on the toolbar "Form Design" - the icon looks like a rectangle with a compass in the upper right corner; if the form navigator icon is grayed out, the first press the design mode on/off icon all the way on the left or top, looks like a triangle with a pencil) In the form navigator, right-click on the form's name and choose "Properties", then go to the tab "Events" to see the events you can attach a macro to.

I'm not sure how Excel would react to opening a file with a Calc form in it, though.

For getting out of print preview mode, have you tried the dispatcher call .uno:ClosePreview? From reading this thread you may have to add a wait into your code somewhere to prevent crashing.

Re: HELP WITH MACROS

Posted: Thu Aug 27, 2015 1:45 pm
by MATT.B
because of the difference in the programs I have actually crated 2 docs one for oo and one for excel ill give that a try and see how it works

Re: HELP WITH MACROS

Posted: Thu Aug 27, 2015 2:08 pm
by MATT.B
MTP wrote:(To create a form, open the form navigator, right-click on the work "Forms" and choose New->Form;
I don't understand this step where and I right clicking I mean I know how to open all the form toolbars but this step CONFUSES ME


ok I like I actually think I figured this out on my own I just used form navigator to create the new form

Re: HELP WITH MACROS

Posted: Thu Aug 27, 2015 2:14 pm
by MATT.B
MTP wrote:For getting out of print preview mode, have you tried the dispatcher call .uno:ClosePreview? From reading this thread you may have to add a wait into your code somewhere to prevent crashing.
No that is the command I think I have been looking for I learned basic on excel by messing around with it still new but I can do some cool stuff with it but switching to oo the communication commands are very different even a little more complicated thank you