Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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 opene

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   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 you for ur reply!
--
cj


"Peter T" wrote:

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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Is it a bug? in VBA, FileName (with "[", "]") changes after opene

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
  #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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"CELL("FILENAME") NOT UPDATE AFTER "SAVE AS" ACTION yossie6 Excel Discussion (Misc queries) 1 June 16th 08 12:16 PM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 11:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"