PDA

View Full Version : Bug in "find a deadlink" macro



tartopwaro
07-31-2013, 10:43 PM
Hello :-)
I am actually struggling with a macro which doesn't seem to work :banghead:
Could you please look at my code and maybe help me ?
The error code is the error 91
it happens from the debug.print line
and I guess it's LinkFormat.SourceFullName which has a bug

I dunnooooooo ouahh


the macro :

Find broken links on a word file and list them in a Csv file.

the code :


Sub Deadlink()
Dim Doc As Document
Dim img As InlineShape
Dim docwimg As Document

'Affect object
Set docwimg = ActiveDocument
Set cvslist = Documents.Add

'For Each img
For Each img In docwimg.InlineShapes

'Control
Debug.Print "Image : " & img.LinkFormat.SourceFullName & " -- " & Dir(img.LinkFormat.SourceFullName)

'Test
If Dir(img.LinkFormat.SourceFullName) = "" Then
'Écriture dans le document si image non présente
cvslist.Range.Select
Selection.Collapse (wdCollapseEnd)
Selection.TypeText img.LinkFormat.SourceFullName & vbCrLf
End If

Next img

'Save
cvslist.SaveAs2 "C:\Temp\error_report.csv", wdFormatDOSText

'Close
cvslist.Close
Set cvslist = Nothing

End Sub


Any idea ? : pray2: Oh, I'm on Office 2010!

tartopwaro
08-01-2013, 02:18 AM
No replies ? one part of the problem is that it's Includepictures.
not real links (?)

Could someone help me with that problem ?

fumei
08-01-2013, 04:54 PM
one part of the problem is that it's Includepictures.
not real links (?)


It is not ONE part of the problem...it IS the problem. If they are not links why would you think LinkFormat would be valid?

tartopwaro
08-01-2013, 06:02 PM
one part of the problem is that it's Includepictures.
not real links (?)


It is not ONE part of the problem...it IS the problem. If they are not links why would you think LinkFormat would be valid?

yep...
I dunno why, but I was sure it was hyperlinks (well I was told, then someone told me "eyh, it's include pic ! that's why it won't work !"

:think:

it doesn't work... because I know that I don't know how to adapt the code correctly


Sub find_dead_link()

' find_dead_link Macro
Dim Dimg As Document
Dim Fld As Field
Dim stPath As String

'Affect objects
Set Dimg = ActiveDocument
Set CSV = Documents.Add

'Boucle sur les images
For Each Fld In Dimg.Fields
stPath = Fld.Code

'Debug
Debug.Print LTrim(Replace(stPath, "INCLUDEPICTURE ", ""))

'Test
If Fld.Code = "" Then
'Ecriture dans le document si image non presente
CSV.Range.Select
Selection.Collapse (wdCollapseEnd)
Selection.TypeText Fld.Code & vbCrLf
End If

Next Fld


'Save the file
CSV.SaveAs2 "C:\Documents and Settings\error_report.csv", wdFormatDOSText


'Close the file
CSV.Close
Set CSV = Nothing


End Sub

fumei
08-02-2013, 05:29 PM
So now what are you getting

fumei
08-03-2013, 12:06 AM
I am not really following what you are doing. If they are fields with INCLUDEPICTURE, and the images are there, then by definition there are no "dead" links. They are there so the link can not possibly be "dead"
But you can try:

stPath = Fld.LinkFormat.SourceFullName