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

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
56
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
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,989
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
That should work fine, assuming the drive mapping is correct on all machines that might be using the code.
 

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
56
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 :/
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
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
 

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
56
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?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,989
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Try replacing this:

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

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

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
56
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:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,989
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
I'd assume they'd need at least read access to the files.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,362
Messages
5,468,175
Members
406,569
Latest member
Quest_

This Week's Hot Topics

Top