Closed Fr4nc01s closed 6 years ago
This is good stuff
Sent from my stupid Android phone using Microsoft Outlook which wasn't written by Microsoft but, rather, a third party and is very buggy. Please bring back the Windows Phone!! Best phone ever!!
On Thu, Aug 2, 2018 at 1:51 PM -0700, "Fr4nc01s" notifications@github.com wrote:
For those writing macros using VBA with Word, Excel, etc and have faced this error when executing your macro:
Documents.Open (..)
error 5174 Sorry, we couldn't find your file. Was it moved, renamed, or deleted?
("drive letter:...\filename...")
I have seen a lot of posts around this error. There are 2 main scenarios, and the easiest one is the only one that is getting discussed.
Scenario 1
You are trying to open a "path\file" name that has actually moved between the time your program started and came up with the "path\file" name value, and the time it actually tried to open the file. That is easy to fix.
Scenario 2
THE MOST IMPORTANT ONE AND MOST DIFFICULT TO DETECT
The value you are using to designate the "path\file" name to open using your macro code such as:
Documents.Open (....
...said value contains non printable characters (I am not talking about non alphanum like "." or "&, or characters not allowed, I am talking about ASCII 13 most likely being the last character at the end of the value for your filename. But when you use Debug.Print, that character is not printed.
Steps To Confirm:
When you are in debug mode, Debug.Print "the value of the path\file you are trying to open".
This will print as expect with no visible issues, you can then confirm the file exists by copy pasting the printed value in windows explorer and the file should open automatically. If it does open manually, then you are likely dealing with scenario #2
THEREFORE
while in debug mode, using the variable that contains the path\file vallue, write a FOR statement to iterate through each character of the string using Debug.Print Asc(<>), where <> is the variable in the FOR iteration that gets assigned 1 character from the path\file string at a time. Most likely you will see the last character will print as 13
The VBA function
Trim(....
does not take care of this problem. you need to use the
Replace (...
function with "Chr(13)" as the value sought to be replaced with vbNullString
There are some hacks that consist in adding ASCII char 13 (carriage return, without a line fee) to file names and then appending the name, etc
There are utilities that clean those issues up, maybe not completely?... this might be the cause.
Another possible cause in my radar is the DOS prompt adding an extra char 13 when redirecting the output of a DIR command using ">>" into a file to create a list of files from the DIR command. It does not happen for all files in the results of the DIR command, it could be for files having special characters that are allowed. I do not have the time to investigate that further.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Hi SixSigmaGuy,
I am writing to ask for your help in raising awareness to the misleading solution below that has been viewed 55K times on the site, I followed this approach as I resumed programing after 8 years... and it wasted a lot of my time (and I think the time of 20-30K other people)...
I have posted (see below for link) a much safer, faster and easier to maintain approach (probably what was intended by the authors of the object model).
I you could please increase the ranking of the answer I provided for future readers' sake.
https://stackoverflow.com/a/51756686/10173250
Thanks in advance.
From: SixSigmaGuy notifications@github.com Sent: August 2, 2018 2:58 PM To: OfficeDev/VBA-content Cc: Fr4nc01s; Author Subject: Re: [OfficeDev/VBA-content] Sorry, we couldn't find your file. Was it moved, renamed, or deleted? (#637)
This is good stuff
Sent from my stupid Android phone using Microsoft Outlook which wasn't written by Microsoft but, rather, a third party and is very buggy. Please bring back the Windows Phone!! Best phone ever!!
On Thu, Aug 2, 2018 at 1:51 PM -0700, "Fr4nc01s" notifications@github.com wrote:
For those writing macros using VBA with Word, Excel, etc and have faced this error when executing your macro:
Documents.Open (..)
error 5174 Sorry, we couldn't find your file. Was it moved, renamed, or deleted?
("drive letter:...\filename...")
I have seen a lot of posts around this error. There are 2 main scenarios, and the easiest one is the only one that is getting discussed.
Scenario 1
You are trying to open a "path\file" name that has actually moved between the time your program started and came up with the "path\file" name value, and the time it actually tried to open the file. That is easy to fix.
Scenario 2
THE MOST IMPORTANT ONE AND MOST DIFFICULT TO DETECT
The value you are using to designate the "path\file" name to open using your macro code such as:
Documents.Open (....
...said value contains non printable characters (I am not talking about non alphanum like "." or "&, or characters not allowed, I am talking about ASCII 13 most likely being the last character at the end of the value for your filename. But when you use Debug.Print, that character is not printed.
Steps To Confirm:
When you are in debug mode, Debug.Print "the value of the path\file you are trying to open".
This will print as expect with no visible issues, you can then confirm the file exists by copy pasting the printed value in windows explorer and the file should open automatically. If it does open manually, then you are likely dealing with scenario #2
THEREFORE
while in debug mode, using the variable that contains the path\file vallue, write a FOR statement to iterate through each character of the string using Debug.Print Asc(<>), where <> is the variable in the FOR iteration that gets assigned 1 character from the path\file string at a time. Most likely you will see the last character will print as 13
The VBA function
Trim(....
does not take care of this problem. you need to use the
Replace (...
function with "Chr(13)" as the value sought to be replaced with vbNullString
There are some hacks that consist in adding ASCII char 13 (carriage return, without a line fee) to file names and then appending the name, etc
There are utilities that clean those issues up, maybe not completely?... this might be the cause.
Another possible cause in my radar is the DOS prompt adding an extra char 13 when redirecting the output of a DIR command using ">>" into a file to create a list of files from the DIR command. It does not happen for all files in the results of the DIR command, it could be for files having special characters that are allowed. I do not have the time to investigate that further.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FOfficeDev%2FVBA-content%2Fissues%2F637%23issuecomment-410065830&data=02%7C01%7C%7Ccd16df6dfbdf434a69dd08d5f8baaccb%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636688402993568011&sdata=%2BfM%2B0e5LsQiyOQijMpoCft7Ywd1BWWQTUbrdwnkGS38%3D&reserved=0, or mute the threadhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAoGW8S3OeQgjMRe37ZfBkni1q3rWvOpMks5uM2fqgaJpZM4Vs-_1&data=02%7C01%7C%7Ccd16df6dfbdf434a69dd08d5f8baaccb%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636688402993568011&sdata=m9RUyMEHK7Au57q%2BuDRnaZeT3OlK5bbDqBLQIalPKis%3D&reserved=0.
Thanks for your contribution! This content has migrated to https://github.com/MicrosoftDocs/VBA-Docs. Please go to the new repo, and if you still see the issue occuring there, please open a brand new issue. Closing this issue now. Regards, lindalu
For those writing macros using VBA with Word, Excel, etc and have faced this error when executing your macro:
Documents.Open (..)
error 5174 Sorry, we couldn't find your file. Was it moved, renamed, or deleted? ("drive letter:...\filename...")
I have seen a lot of posts around this error. There are 2 main scenarios, and the easiest one is the only one that is getting discussed.
Scenario 1 You are trying to open a "path\file" name that has actually moved between the time your program started and came up with the "path\file" name value, and the time it actually tried to open the file. That is easy to fix.
Scenario 2 THE MOST IMPORTANT ONE AND MOST DIFFICULT TO DETECT The value you are using to designate the "path\file" name to open using your macro code such as: Documents.Open (.... ...said value contains non printable characters (I am not talking about non alphanum like "." or "&, or characters not allowed, I am talking about ASCII 13 most likely being the last character at the end of the value for your filename. But when you use Debug.Print, that character is not printed.
Steps To Confirm: When you are in debug mode, Debug.Print "the value of the path\file you are trying to open".
This will print as expect with no visible issues, you can then confirm the file exists by copy pasting the printed value in windows explorer and the file should open automatically. If it does open manually, then you are likely dealing with scenario #2
THEREFORE while in debug mode, using the variable that contains the path\file vallue, write a FOR statement to iterate through each character of the string using Debug.Print Asc(<>), where <> is the variable in the FOR iteration that gets assigned 1 character from the path\file string at a time. Most likely you will see the last character will print as 13
The VBA function Trim(....
does not take care of this problem. you need to use the Replace (...
function with "Chr(13)" as the value sought to be replaced with vbNullString
There are some hacks that consist in adding ASCII char 13 (carriage return, without a line fee) to file names and then appending the name, etc
There are utilities that clean those issues up, maybe not completely?... this might be the cause.
Another possible cause in my radar is the DOS prompt adding an extra char 13 when redirecting the output of a DIR command using ">>" into a file to create a list of files from the DIR command. It does not happen for all files in the results of the DIR command, it could be for files having special characters that are allowed. I do not have the time to investigate that further.