View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Is it a bug? in VBA, FileName (with "[", "]") changes after opene

Not sure if it's a bug or VBA trying to being helpful.
I tried to manually to SaveAs "abc[def]gh.xls" and got a message telling me
(in effect) the following characters are illegal
< ? [ ] : | or *

Some of those characters are indeed illegal in any filename and it's not an
exhaustive list. However it is possible to save (say) a text file with
square brackets or rename an xls with them.

I notice if I open an xls that I had renamed to include [ & ], Excel's
window caption shows square brackets but in the VBE window captions renamed
( & ), returning it's name in VBA gives round brackets.

Regards,
Peter T

"iop" wrote in message
...
in Excel VBA macro, I found:
here is a file named "abc[def]gh.xls" in folder_A,
1. Code1:
for each objFile in folder_A.files
when objFile refers to this file, its Name property objFile.Name =
"abc[def]gh.xls", which is correct.
2. Code2:(if we open this file, its name changes.)
set objFile = application.open(objFile)
when objFile refers to this file, after running this code, objFile.Name

=
"abc(def)gh.xls", here, "[" and "]" have changed to "(" and ")".

I've check it in both excel 2003 and 2007, the same result.

Is this a bug? or on some intended purpose?

thanks!
--
cj