[SOLVED] Two macros lost, I have a backup

Discuss setup / installation issues - Add a spell checker, Language pack?
Post Reply
M4x_
Posts: 18
Joined: Wed Nov 07, 2018 8:40 am

[SOLVED] Two macros lost, I have a backup

Post by M4x_ »

Hi all, I got useful help in the past so I come back at you - hoping it's not a big deal to fix this issue.

After a power shortage with OO documents (saved as .odt) opened or maybe after a Win7 update,
2 macros in OO writer are not working anymore.
I read some posts so I could locate my 2 macros in C:\Users\MAX\AppData\Roaming\OpenOffice\4\user\basic\Standard .
They are still there, just not working anymore, so I'm gonna provide you further details.


OS: windows 7
OpenOffice 4.1.7
Macros relate to : OO Writer
Macros are not anymore present under Tools > Macro. I think I checked correctly any sub directory.
(this meaning I cannot run the macro manually, navigating under the directories) .

Shortcuts assigned : F4 and F8 . Hitting them return this error code : https://imgur.com/hqcyZff
PREMACRO is the first macro and it was assigned to F4, KEYWORDS is the second one, assigned to F8.
They were running smoothly before.

Finally: the code has been someway been edited and I cannot fix it.
I went on a working copy of the macro and tried to edit the first error I could understand, which was : " was expressed as plain text .
I fixed it with a find and replace , that worked but the next error was something like CTIL expected and here I am.

Let me know and I'd be glad to provide whatever detail I can.
Cheers !

I cannot attach XBA and XLB neither relative txt files so I paste here the code so you can have a look at the macros.
We're talking about a couple formatting macros : PREMACRO and CAPSBOLD + 1 that searches some 10-15 keywords in a given text: KEYWORDS.
Only PREMACRO and KEYWORDS were assigned a special key to recall them.
THere's also a macro called DELETE and that has not to be considered.


**************************************************************************

FILE A: TRANSCRIPT.xba (main file)

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TRANSCRIPT" script:language="StarBasic">sub KEYWORDS()

oDoc = ThisComponent
oBank = Array("interesting", "possibility", "obvious", "quality", "because", "why", "false", "trap", "window", "five-minute", "news", "short seller", "short sellers",  "squeeze", "squeezes", "halt", "halts", "short", "share seller", "sellers", "000 share", "the ask", "the bid", "bids", "hitting", "cover", "spread", "hidden", "borrow", "level two", "tape", "level too", "level 2", "pattern", "setup ", "strategy", "pivot", "citron", "hedge fund", "filing", "secondary", "small cap", "moving average", "tesla", "ipob", "hyln",  "mike")

for i =0 to ubound(obank) &apos;prepare regex string
if i<>0 then st = st & "|"
st = st & "\b" & obank(i) & "\b"
next

oDesc = oDoc.createSearchDescriptor()
odesc.SearchRegularExpression = true
odesc.searchstring = st
   oFound = oDoc.findAll(oDesc)
   If oFound.Count > 0 Then
      For i = 0 to oFound.Count -1
         oInstance = oFound.getByIndex(i)
         oInstance.CharColor = RGB(255 ,0, 0)
      next i
   End If

End Sub

sub PREMACRO
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(18) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(3).Name = "SearchItem.AllTables"
args2(3).Value = false
args2(4).Name = "SearchItem.Backward"
args2(4).Value = false
args2(5).Name = "SearchItem.Pattern"
args2(5).Value = false
args2(6).Name = "SearchItem.Content"
args2(6).Value = false
args2(7).Name = "SearchItem.AsianOptions"
args2(7).Value = false
args2(8).Name = "SearchItem.AlgorithmType"
args2(8).Value = 1
args2(9).Name = "SearchItem.SearchFlags"
args2(9).Value = 65536
args2(10).Name = "SearchItem.SearchString"
args2(10).Value = "$"
args2(11).Name = "SearchItem.ReplaceString"
args2(11).Value = " "
args2(12).Name = "SearchItem.Locale"
args2(12).Value = 255
args2(13).Name = "SearchItem.ChangedChars"
args2(13).Value = 2
args2(14).Name = "SearchItem.DeletedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.InsertedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.TransliterateFlags"
args2(16).Value = 1280
args2(17).Name = "SearchItem.Command"
args2(17).Value = 3
args2(18).Name = "Quiet"
args2(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageUp", "", 0, Array())

end sub

sub CAPSBOLD
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Bold"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:Bold", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(2) as new com.sun.star.beans.PropertyValue
args3(0).Name = "FontHeight.Height"
args3(0).Value = 9
args3(1).Name = "FontHeight.Prop"
args3(1).Value = 100
args3(2).Name = "FontHeight.Diff"
args3(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(2) as new com.sun.star.beans.PropertyValue
args4(0).Name = "FontHeight.Height"
args4(0).Value = 10
args4(1).Name = "FontHeight.Prop"
args4(1).Value = 100
args4(2).Name = "FontHeight.Diff"
args4(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args4())

end sub

sub DELETE
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())

end sub
</script:module>
*************************************************************************

FILE B : AltSearchBatchs.xba

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AltSearchBatchs" script:language="StarBasic">REM  *****  BASIC  *****
Option Explicit

&apos; Warning this module is modified by execution of AltSearch macro!
&apos; Contains subroutines for assign key shortcut for AltSearch&apos;s batchs.
&apos; Do not change any character unless you know what you do!

Sub Altsearch___dialog
 On Error resume next
 GlobalScope.BasicLibraries.LoadLibrary("AltSearch") &apos;load AltSearch library
 _AltSearch
End sub

Sub Altsearch___Find_next
 On Error resume next
 GlobalScope.BasicLibraries.LoadLibrary("AltSearch")
 _FindNext
End sub

Sub Altsearch___Find_previous
 On Error resume next
 GlobalScope.BasicLibraries.LoadLibrary("AltSearch")
 _FindBack
End sub
</script:module>
*************************************************************************

FILE C: script.xlb

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="Standard" library:readonly="false" library:passwordprotected="false"/>
**************************************************************************
FILE D: dialog.xlb (the last one in the directory)

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="Standard" library:readonly="false" library:passwordprotected="false"/>
**************************************************************************
Last edited by robleyd on Tue Oct 27, 2020 12:00 am, edited 4 times in total.
Reason: Add green tick
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Two macros lost , I have a backup

Post by Villeroy »

Restore the entire directory %APPDATA%\OpenOffice\4\user\basic from your backup medium.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
M4x_
Posts: 18
Joined: Wed Nov 07, 2018 8:40 am

Re: Two macros lost , I have a backup

Post by M4x_ »

Thanks for the help in displaying the code.
My backup is the 4 files I included in the message above.
It's all I have and it's exactly the dir you asked me to substitute,
meaning it would be an overwrite, with same content.
I'm sorry if I expressed myself incorrectly.
OpenOffice 4.1.7
John_Ha
Volunteer
Posts: 9604
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Two macros lost , I have a backup

Post by John_Ha »

My AOO macros are stored in C:\Users\John\AppData\Roaming\OpenOffice\4\user\basic\Standard\Module1.xba. I have a dialog.xlb and a script.xlb which are unchanged since AOO installed.
Clipboard02.gif
Open it with Notepad and you should see something like below, with Sub Main ... End Sub and a macro name.
Clipboard01.gif
That being said you can store macros anywhere if you override the default path offered. Macros can either be stored globally, for use in any document (as mine are); or locally in a document .odt file, in which case they are only available when that document is being edited.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Two macros lost , I have a backup

Post by Villeroy »

Another Windows user without proper backup strategy. :(
Open the XML in a text editor and replace all occurrances of " with a double quote. Then copy everything within the <script> tags into the StarBasic editor.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
M4x_
Posts: 18
Joined: Wed Nov 07, 2018 8:40 am

Re: [SOLVED] Two macros lost, I have a backup

Post by M4x_ »

Thanks everyone.
OpenOffice 4.1.7
Post Reply