Update links only if file exists

  • Thread starter Thread starter Greg H.
  • Start date Start date
G

Greg H.

I have built a Year to date report for my department that I send out on a
monthly basis. The main file pulls data from other documents to compile
everything. Because I know the name of every file it will pull from (its not
hard with you watched Sesame Street and learned your months) I set up all the
equations in the future months to already pull from those files. Problem is
when I open the document and select update links, it errors out once I come
to a file it can not find. Is there a way for it to skip over a file if it
does not exists and continue to look for the other files, updated those that
are there?
 
Use a simple function like this:

Function bFileExists(ByVal sFile As String) As Boolean

Dim lAttr As Long

On Error Resume Next
lAttr = GetAttr(sFile)
bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0

End Function

Use it like this:

If bFileExists(yourfilepath) then
'do whatever code needs doing here
Else
'Skip the file
End If


RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Windows 11 Windows 11 update 5
Windows 10 Windows 10 October 2018 update now available !!!!!!!!! 3
Updateing file links 2
How do find text with sumproduct if possible 11
Complicated Save 1
Error can't Find File 2
Help with XLT file 2
User Selected Month 5

Back
Top