Results 1 to 6 of 6

Thread: [RESOLVED] Checking hyperlinks

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Resolved [RESOLVED] Checking hyperlinks

    Hi,

    I am novice using vbscript and I m blocked to write a script for checking hyperlinks in doc file (word)
    Maybe someone can help me
    I have written a piece of code but I want to automize it.
    What I do is checking hyperlinks in a doc file and write the result in a htm file.
    For this it's ok
    But what I want to do is checking all hyperlinks of all doc files (word) for a whole directory (ex : all word files present in C:\Temp)
    I don't know if it's possible (I have more than 100 doc files to check and I don't want to specify manually all fiels to be checked)
    This is what I have written :
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Set objWord = CreateObject("Word.Application")
    objWord.Visible = FALSE

    Set objDoc = objWord.Documents.Open("C:\Temp\auto.doc")

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\temp\chklinks.htm", ForWriting, True)

    Set colHyperlinks = objDoc.Hyperlinks
    For Each objHyperlink in colHyperlinks
    objFile.WriteLine "<a href=" & chr(34) & objHyperlink.Address & Chr(34) & ">" & _
    objHyperlink.TextToDisplay & "</a href><br>"
    Next

    objFile.Close

    Set objDoc = objWord.Documents.Open("C:\Temp\maison.doc")

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\temp\chklinks.htm", ForAppending, True)

    Set colHyperlinks = objDoc.Hyperlinks
    For Each objHyperlink in colHyperlinks
    objFile.WriteLine "<a href=" & chr(34) & objHyperlink.Address & Chr(34) & ">" & _
    objHyperlink.TextToDisplay & "</a href><br>"
    Next


    objFile.Close

    Thanks a lot
    Sergio

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Checking hyperlinks

    Moved to office development.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Checking hyperlinks

    how do you want it automated?
    as such, for instance when you open and excel file?
    to just run from one location? i.e. and exe file?

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Re: Checking hyperlinks

    Hi,

    I want to execute this when opening an excel file.
    The directory wich contains doc files to be checked will be always the same (ex : C:\Temp) but doc files may change.
    So I want first to list all *doc for this directory and check hyperlinks of those doc files only.
    I don't know if it's clear but my english is not so good :-) sorry for this

    If you need more info let me know I will try to explainbetter or give some example

    Thanks for your help

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Checking hyperlinks

    vb Code:
    1. mypath = "C:\temp\"
    2. mydoc = dir(mypath & "*.doc")  ' get first doc file
    3. do while len(mydoc) > 0
    4.   Set objDoc = objWord.Documents.Open(mypath & mydoc)
    5.   ' your code here
    6.   objdoc.close
    7.   mydoc = dir  ' get next file
    8. loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Re: Checking hyperlinks

    Hi,

    Thanks for your support. The 'Dir' comands was not supported by vbscript but I found a workaround.
    I will close the topic, thanks one more time

    Regards

Posting Permissions

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



Click Here to Expand Forum to Full Width