質問する

Mr Spock's profile - activity

2017-08-04 12:30:11 +0200 バッジを受け取った  卓越した質問 (source)
2017-05-07 07:07:31 +0200 バッジを受け取った  人気の質問 (source)
2017-01-02 03:24:54 +0200 バッジを受け取った  有名な質問 (source)
2016-10-04 12:04:11 +0200 バッジを受け取った  サポーター (source)
2016-10-04 06:38:31 +0200 バッジを受け取った  卓越した質問 (source)
2016-10-04 06:38:30 +0200 バッジを受け取った  熱心な人
2016-10-03 23:52:34 +0200 コメント付き回答 Macro code to switch between open Writer documents

@Lupp: I agree about this site and on-going dialog. I attempted to post my last answer as a comment and hit the character limit. I came here because I am still unsure of the difference (if any) between Libre Office, Open Office, Star Office and all the other flavours. Meantime I will still search for the "Dummies Guide to OpenOffice Object Model".

2016-10-03 05:06:18 +0200 バッジを受け取った  卓越した質問 (source)
2016-10-03 03:17:59 +0200 バッジを受け取った  人気の質問 (source)
2016-10-03 02:44:49 +0200 質問に回答する Macro code to switch between open Writer documents

Using Frames led us up a blind alley!

I have made progress! After numerous Google searches and consulting Andrew Pitonyak's excellent reference Open Office Macros Explained, I have reached this point:

GlobalScope.BasicLibraries.LoadLibrary("Tools")     'Contains FileNameOutOfPath
vComponents = StarDesktop.getComponents()           'Get all the components
vDocs = vComponents.createEnumeration()             'Enumerate them

Do While vDocs.hasMoreElements()                    'While there are more
    vDoc = vDocs.nextElement()                      'Get the next component
    If vDoc.SupportsService("com.sun.star.text.TextDocument") Then
        if vDoc.GetBookmarks().GetCount <> 0 then
            vBookmarks = vDoc.GetBookmarks()
            for i = 0 to vBookmarks.getCount() -1
                vBM = vBookmarks.getbyIndex(i)
                vBM.getAnchor.setString("(" & Now() & ": " & vBM.Name & ")")
            next
        end if
    End If
Loop

This code loops through my open documents, finds all bookmarks and inserts text at those bookmarks. My next challenge is manipulating tables in the documents.

During this process I came across numerous comments from others about how poorly the Object model is documented. The most frustrating aspect is no consistency. EG: using .createEnumeration() works in some places but not others. One commentor made the observation that a big issue holding Open Office/Libre Office back in the commercial world is the very steep learning curve for OO/LO Basic vs MS Office VBA. I agree. I have written numerous macros in MS VBA. In the VBA object browser you can inspect any object to determine the correct syntax.

2016-10-02 12:04:07 +0200 質問をする Macro code to switch between open Writer documents

I have several documents open. I need to reference bookmarks and tables in any document from any other document. For example, I have six documents open. From doc #2 I want to reference bookmarks and tables in doc #5. From doc #3 reference bookmarks in doc #1 and tables in doc #4. Macro code can be executed from any document.

Here is where I have got to: This allows me to loop through open documents and get window names

Frames = Stardesktop.Frames
For i = 0 to Frames.Count - 1
   Frame = Frames.getByIndex(i)
   print Frame.Title
       ' code here to make this doc active
next i

Am I one the right path using Stardesktop.Frames? What code will make the document the active one?

Is there a better way?

All advice and assistance greatly appreciated

2016-10-01 13:49:42 +0200 バッジを受け取った  人気の質問 (source)
2016-10-01 13:35:36 +0200 質問に回答する Macro to get default template location

Thank you both JohnSUN and pierre-yves samyn.

You have pointed me in the right direction

Here is my test code:

Sub PathTesting
Dim oSettings as Object
dim oContext as object
Dim sTemplate as String
Dim sTempFolder as String

    oSettings = createUnoService("com.sun.star.util.PathSettings")
    oContext = GetDefaultContext.getByName("/singletons/com.sun.star.util.thePathSettings")

    sTemplate = oSettings.template_writable
    sTempFolder = oContext.temp_writable

    msgbox "Templates: " & sTemplate & chr(13) & "Temp Folder: " & sTempFolder

End Sub

Here is why I am having difficulty getting my head around LO Basic. Both createUnoService("com.sun.star.util.PathSettings") and GetDefaultContext.getByName("/singletons/com.sun.star.util.thePathSettings") give the same results. Which one to use? I will be including some macro code in a document I want to distribute to numerous users. I want it to be as bullet proof as possible. Will either command work with all versions of Libre Office?

2016-10-01 12:35:07 +0200 バッジを受け取った  学者 (source)
2016-10-01 10:38:15 +0200 質問をする Macro to get default template location

I have been trying to find the correct macro syntax to get the default template folder location ie: the path setting in Options > LibreOffice > Paths > Templates

2016-09-28 23:55:47 +0200 コメント付き回答 Macro code to access bookmarks in another document

PS: What is the protocol for marking a question as [closed]?

2016-09-28 23:50:09 +0200 質問に回答する Macro code to access bookmarks in another document

Thank you mark_t that works.

I am still trying to understand the LO object model. I have been reading Andrew Pitonyak's book and recording macros to attempt to gain a better understanding of LO macros but there are times when my old addled brain fails me!

2016-09-28 23:19:13 +0200 質問をする Macro code to access bookmarks in another document

From my main document "CreateBookmarks" my macro code creates a new document based on a template "Bookmarks" that contains several bookmarks. I am having difficulties referring to these bookmarks.

Here is my test code contained in "CreateBookmarks":

Sub CreateBookmarkDoc

    Dim sURL as String
    Const sPathName = "F:\Users\ifsian\Documents\OpenOffice\Templates\Bookmarks.ott"

    sURL = ConvertToURL(sPathName)
    StarDesktop.loadComponentFromURL(sURL,0,"_default",Array())

    msgbox "Bookmark Count: " & ThisComponent.getBookmarks().getcount()

End Sub

When executed in the original document, ThisComponent.getBookmarks().getcount() returns 0. If the above code is copied into a module under MyMacros and Dialogs and executed it works. A new document is created and the count of bookmarks in the document just created returned. I am guessing ThisComponent.getBookmarks().getcount() is counting bookmarks in the original document rather than the document just created even though this document has focus.

My question is:

What is the correct syntax to access bookmarks in another document?

Edited format of code block. mark_t