1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Using VBS to manipulate OpenOffice

Discussion in 'Software Development' started by JuniperGreen, Jan 15, 2013.

Thread Status:
Not open for further replies.
  1. JuniperGreen

    JuniperGreen Thread Starter

    Joined:
    Jan 3, 2013
    Messages:
    25
    I have been using a VBScript to extract a list of any hyperlinks and their associated "Display Text" where they occur in MS Word docs. I have been asked to set this up for someone else but discovered that they do not MS Word as they use OpenOffice (.odt docs). I understand that it is quite possible to do this but I have not been able to do so so far. Does anyone know how to modify my VBScript so that it will work with OpenOffice? I have appended the script I use with Word (it ain't great but it does the business!).

    I have managed to open an "odt" file in OpenOffice but that is as far as it goes. I'm stumped and there does not appear to be much in the way of info as to how the hyperlinks extracted although I understand VBS is more or less compatible.

    I would appreciate any help on this or a script if anyone has achieved this

    Thank you



    Code:
     For Word
    'To be run at CMD Prompt:  cscript ExtractHyperLinks.vbs >> HyperOut.txt
    
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    
    Dim Gap
    Dim Item
    Dim Ref
    
    Gap = "   "
    Item = "Item: "
    Ref = "URL: "
    
    Set objDoc = objWord.Documents.Open("F:\sun-130113\Atlantis - Wiki.doc")
    
    Set colHyperlinks = objDoc.Hyperlinks
    
    For Each objHyperlink in colHyperlinks
    
    Set objStdOut = WScript.StdOut
      
    objStdOut.Write Item
    objStdOut.Write objHyperlink.TextToDisplay
    objStdOut.write Gap
    objStdOut.Write Ref
    objStdOut.Write objHyperlink.Address
     objStdOut.WriteBlankLines(2)
    
    Next
    

    Code:
     For OpenOffice
    Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
    
    Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
    
    Dim args()
    Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter",_
                     "_blank", 0, args)
    
    Set objText= objDocument.getText
    
    Set objCursor= objText.createTextCursor
    
    Sub Run(ByVal sFile)
    
    Dim shell
    
        Set shell = CreateObject("WScript.Shell")
        shell.Run Chr(34) & sFile & Chr(34), 1, false
        Set shell = Nothing
    End Sub
    
    Run "F:\Sun-130113\MyFile.odt"
    
    Set objODT = objswriter.documents.Open("F:\sun-130113\MyFile.odt")
    
    Set colHyperlinks = objOdt.Hyperlinks
    
    For Each objHyperlink in colHyperlinks
    
    Set objStdOut = WScript.StdOut
      
    objStdOut.Write Item
    objStdOut.Write objHyperlink.TextToDisplay
    objStdOut.write Gap
    objStdOut.Write Ref
    objStdOut.Write objHyperlink.Address
     objStdOut.WriteBlankLines(2)
    
    Next
    
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Using manipulate OpenOffice
  1. adhya.arya
    Replies:
    2
    Views:
    221
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1085369

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice