|
-
Mar 5th, 2010, 02:42 AM
#1
Thread Starter
New Member
[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
-
Mar 8th, 2010, 08:00 AM
#2
Re: Checking hyperlinks
Moved to office development.
-
Mar 8th, 2010, 08:12 AM
#3
Hyperactive Member
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?
-
Mar 9th, 2010, 06:22 PM
#4
Thread Starter
New Member
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
-
Mar 10th, 2010, 05:09 AM
#5
Re: Checking hyperlinks
vb Code:
mypath = "C:\temp\" mydoc = dir(mypath & "*.doc") ' get first doc file do while len(mydoc) > 0 Set objDoc = objWord.Documents.Open(mypath & mydoc) ' your code here objdoc.close mydoc = dir ' get next file 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
-
Mar 10th, 2010, 07:14 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|