Msgbox to also show pdf number thats missing

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

Using the code below i am trying to have a msgbox pop up with a message & also the number of the pdf that ive been advised wasnt found

Rich (BB code):
Private Sub HyperlinkInvoiceNumber_Click()
Dim lastRow As Long
Dim myPath As String, fileName As String


myPath = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" 'FOLDER LOCATION OF WHERE PDF ARE SAVED
lastRow = Range("P" & Rows.Count).End(xlUp).Row

For i = 6 To lastRow

    fileName = myPath & Range("P" & i).Value & "*.pdf"
    
    If Len(Dir(fileName)) <> 0 Then 'IF THE PDF FILE EXISTS THEN
    
        ActiveSheet.Hyperlinks.Add Range("P" & i), myPath & Dir(fileName)
        Else
      MsgBox "PDF DOES NOT EXIST" & p.Value, vbExclamation, "PDF IS MISSING IN THE FOLDER"
    
    End If
    
Next
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try:
VBA Code:
Private Sub HyperlinkInvoiceNumber_Click()
    Dim LastRow As Long, myPath As String, FileName As String, fName As Variant
    myPath = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" 'FOLDER LOCATION OF WHERE PDF ARE SAVED
    LastRow = Range("P" & Rows.Count).End(xlUp).Row
    For i = 6 To LastRow
        If Not Dir(myPath & Range("P" & i) & ".pdf", vbDirectory) = vbNullString Then
            ActiveSheet.Hyperlinks.Add Range("P" & i), myPath & Range("P" & i) & ".pdf"
        Else
            MsgBox "PDF DOES NOT EXIST " & Range("P" & i), vbExclamation, "PDF IS MISSING IN THE FOLDER"
        End If
    Next i
End Sub
 
Upvote 0
Hi,
That now advises me of the number that wasnt found thanks.

In some cells there will be N/A of which the old code ignored.
This code mentioned above now advises me that the N/A was also not found as like a number.

Can we have the code ignor any cells that have N/A in them.

Thanks
 
Upvote 0
Can you advise on the following please.

I would like the message to advise PDF 123 DOES NOT EXIST

Rich (BB code):
Private Sub HyperlinkInvoiceNumber_Click()
    Dim LastRow As Long, myPath As String, FileName As String, fName As Variant
    
    myPath = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" 'FOLDER LOCATION OF WHERE PDF ARE SAVED
    
    LastRow = Range("P" & Rows.Count).End(xlUp).Row
    For i = 6 To LastRow
    
        If Not Dir(myPath & Range("P" & i) & ".pdf", vbDirectory) = vbNullString Then
            ActiveSheet.Hyperlinks.Add Range("P" & i), myPath & Range("P" & i) & ".pdf"
        Else
            MsgBox "PDF " & Range("P" & i), vbExclamation, "PDF IS MISSING IN THE FOLDER"
        End If
    Next i
End Sub

Currently i can get PDF 123 only without any kind of errors.
Not sure on correct characters to be used in the syntax

Thansk
 
Upvote 0
Try:
VBA Code:
Private Sub HyperlinkInvoiceNumber_Click()
    Dim LastRow As Long, myPath As String, FileName As String, fName As Variant
    myPath = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" 'FOLDER LOCATION OF WHERE PDF ARE SAVED
    LastRow = Range("P" & Rows.Count).End(xlUp).Row
    For i = 6 To LastRow
        If Range("P" & i) <> "N/A" Then
            If Not Dir(myPath & Range("P" & i) & ".pdf", vbDirectory) = vbNullString Then
                ActiveSheet.Hyperlinks.Add Range("P" & i), myPath & Range("P" & i) & ".pdf"
            Else
                MsgBox "PDF " & Range("P" & i) & " DOES NOT EXIST.", vbExclamation, "PDF IS MISSING IN THE FOLDER"
            End If
        End If
    Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top