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

thank u for the answer!
--
cj


"Dave Peterson" wrote:

I wouldn't use [] in filenames.

Excel will use those characters to indicate other workbooks in formulas. And if
your filename uses them, excel could get confused. I bet that's why excel tries
to protect itself by changing them to () when you open the workbook.

='C:\My Documents\Excel\scott\2007\[otherworkbooknamehere.xls]sheet99'!$A$1

I also wouldn't use # in filenames--it can confuse hyperlinks.

iop wrote:

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


--

Dave Peterson