Results 1 to 3 of 3

Thread: Need some help with macro

  1. #1
    Join Date
    Apr 2014
    Location
    "Great North Wet"
    Posts
    133

    Default Need some help with macro

    I have a basic macro that does some things in calc, it works fine but if i open a writer doc it of course crashes. In looking at the ThisComponent i see it has a Title property so i thought, ok, if its the wrong title i will just exit the macro, but no amount of twiddling will let me test this property
    Code:
    Function PortfolioGain() as Currency
       Dim doc As Object
       Dim sheet As Object
       Dim sum as Variant
    
        doc = ThisComponent
        
        if doc.CurrentController.Title != "Stocks.ods" Then 
           Exit Function
         Endif
    I also just noticed that when writer is open and the foreground window that doc (ThisComponent) appears to be null, so i tried this test
    but that also doesnt work.
    Code:
      doc = ThisComponent
        if IsNull(doc) then
           Exit Function
        endif
    What i need to do is to only proceed in the macro if the spreadsheet 'Stocks.ods' is the active sheet
    Can anyone suggest a simple test i could use?
    Turkey Creek Jack Johnson: Nobody move!
    Doc Holliday: Nonsense. By all means, move.

  2. #2
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,857
    Blog Entries
    14

    Default Re: Need some help with macro

    Quote Originally Posted by erbenton View Post
    I have a basic macro that does some things in calc, it works fine but if i open a writer doc it of course crashes. In looking at the ThisComponent i see it has a Title property so i thought, ok, if its the wrong title i will just exit the macro, but no amount of twiddling will let me test this property
    Code:
    Function PortfolioGain() as Currency
       Dim doc As Object
       Dim sheet As Object
       Dim sum as Variant
    
        doc = ThisComponent
        
        if doc.CurrentController.Title != "Stocks.ods" Then 
           Exit Function
         Endif
    I also just noticed that when writer is open and the foreground window that doc (ThisComponent) appears to be null, so i tried this test
    but that also doesnt work.
    Code:
      doc = ThisComponent
        if IsNull(doc) then
           Exit Function
        endif
    What i need to do is to only proceed in the macro if the spreadsheet 'Stocks.ods' is the active sheet
    Can anyone suggest a simple test i could use?
    My 2 cents: go where the experts live, i.e. the libreoffice forums. Your chances will be much higher. In all my years here, I don't think I've seen more than a couple of threads re. LO maxros.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  3. #3
    Join Date
    Apr 2014
    Location
    "Great North Wet"
    Posts
    133

    Default Re: Need some help with macro

    Yup, good idea. I just now posted over on the libre office forum - thanks
    Turkey Creek Jack Johnson: Nobody move!
    Doc Holliday: Nonsense. By all means, move.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •