Cannot find this file. Verify the path and file name are correct

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
71
Hi all,

I have a macro that will open an email template that contains two images as attachments. when putting the images on my local drive the macro runs perfectly. I'm looking to add the images to a shared drive so multiple users can run the macro but when i try adding the new path i'm getting an error 'Cannot find this file. Verify the path and file name are correct'.

The path is "Y:\Folder1\image1.jpg"

Is it possible to reference the image1 if this is located in a shared drive? Below is how i have currently written this in excel

Code:
 msg.attachments.Add "Y:\Folder1\image1.jpg"

thanks in advanced
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
That should work fine, assuming the drive mapping is correct on all machines that might be using the code.
 
Upvote 0
i've checked all users and the mapping is correct but i keep getting that error and i've run out of options to try :/
 
Upvote 0
Long as you have server access permission, something like this might help

Sorry unable to test as this is x64 and the code will not play nicely

Regards
jiuk
Code:
Option Explicit

Sub Test_For_FILE()

Dim mySave_DIR As String
mySave_DIR = "Y:\Folder1\"

If Dir(mySave_DIR) <> "" Then
'// jiuk - Remove MSG after testing
  MsgBox "File Exist"
  
  '// unable to test this code below
  msg.attachments.Add "Y:\Folder1\image1.jpg"
Else
    '// do something
    MsgBox "File does not Exist"
End If

End Sub
 
Upvote 0
Hi jack,

Sorry for the delay in my response. I have used your code but the "File does not Exist" message box is showing. So i'm thinking its something to do with the path its self. Is there another way i can reference a path other than the method we're using?
 
Upvote 0
Try replacing this:

Code:
If Dir(mySave_DIR) <> "" Then

with this:

Code:
If Dir(mySave_DIR, vbdirectory) <> "" Then
 
Upvote 0
I have a small adjustment to inset the image on the active sheet just to see if the image can be found on the local drive and it works but still not working on the shared drive.

Just a though, what permissions would users need to the drive for this to work? at the moment the only permission is "list folder contents"

here's what i've done so far;

Code:
Option Explicit


Sub Test_For_FILE()


Dim mySave_DIR As String
mySave_DIR = "[COLOR=#333333]Y:\Folder1\[/COLOR]"


If Dir(mySave_DIR, vbDirectory) <> "" Then
    Range("A1").Select
    ActiveSheet.Pictures.Insert ("[COLOR=#333333]Y:\Folder1\[/COLOR]image1.jpg")
    MsgBox "File Exist"
Else
    Range("A2").Select
    Selection = "N/A"
    MsgBox "File does not Exist"
End If


End Sub
 
Last edited:
Upvote 0
I'd assume they'd need at least read access to the files.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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