TheSwamp
Code Red => VB(A) => Topic started by: krampaul82 on October 19, 2011, 10:26:46 AM
-
The code below will go into a directory called cut_sheets and delete any existing pdf files and re-populate with the new selection of hyperlinked pdf files. is it possible to skip over or rename any existing pdf files and only add any new hyperlinked pdf files?
Any Help Appreciated......
Option Explicit
Public Sub Gartner_Get_Hyperlink_Main()
Dim objBlock As AcadBlockReference
Dim objEnt As AcadEntity
Dim colHyps As AcadHyperlinks
Dim fso As FileSystemObject
Set fso = New FileSystemObject
If Len(Dir(ThisDrawing.Path & "\Cut Sheets\*.pdf")) <> 0 Then ' Checks to see if there are any PDFs in CURRENT_Project\Cut Sheets\
fso.DeleteFile ThisDrawing.Path & "\Cut Sheets\*.pdf", True ' If there are, delete them
could i rename any existing files or skip over without deleting them and only add only new .pdf's ?
End If
For Each objEnt In ThisDrawing.ModelSpace
If TypeOf objEnt Is AcadBlockReference Then
Set objBlock = objEnt
Set colHyps = objBlock.Hyperlinks
On Error Resume Next ' In case we encounter any blocks that DON'T have hyperlinks
fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\", True ' The TRUE option will automatically overwrite any existing files with the same name
End If
Next objEnt
Set fso = Nothing
End Sub
-
Public Function CheckFilesExistance(strFileName As String) As Boolean
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
CheckFilesExistance = FSO.FileExists(strFileName)
Set FSO = Nothing
End Function
If CheckFilesExistance(strFileName) = True then
Msgbox "Skip existing file"
Else
Msgbox "Do something"
End If
-
Matt
Thank you for your response
what code would I write to skip an existing file?
Mark
-
Matt
Thank you for your response
what code would I write to skip an existing file?
Mark
You could flip it around and do a search for files that DON'T exist.
If Not CheckFilesExistance(strFileName) = True then
Msgbox "Do something"
End If
-
Do I need the message box?
-
No. You would replace it with your code to add new files.
-
You have to look at Copy, CopyFile and Move methods
of FileSystemObject here:
http://msdn.microsoft.com/en-us/library/6tkce7xa(v=VS.85).aspx
HTH
-
Thank You Fixo...
-
With VBA is one relegated to using the FileSystemObject Object, or can the System.IO.File Class be invoked?
-
Also, instead of the sub-routine get/creating the FileSystemObject Object each time it is called, perhaps it is more efficient for the calling function to supply the FSO as an argument with the file path, no?