Using VBS to manipulate OpenOffice

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Top