PC Review


Reply
Thread Tools Rate Thread

Is it a bug? in VBA, FileName (with "[", "]") changes after opene

 
 
iop
Guest
Posts: n/a
 
      17th Dec 2007
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
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      17th Dec 2007
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" <(E-Mail Removed)> wrote in message
news:AB48E61B-40B9-4FD0-ADB8-(E-Mail Removed)...
> 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. Code2if 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




 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Dec 2007
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 With Quote
 
iop
Guest
Posts: n/a
 
      18th Dec 2007
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" <(E-Mail Removed)> wrote in message
> news:AB48E61B-40B9-4FD0-ADB8-(E-Mail Removed)...
> > 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. Code2if 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

>
>
>
>

 
Reply With Quote
 
iop
Guest
Posts: n/a
 
      18th Dec 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
Insert > Autotext is missing "filename" and "filename and path"; how to get back? StargateFan Microsoft Word New Users 7 7th Feb 2005 12:17 AM
DoCmd.TransferText acImportDelim, "spec1", "filetmp","filename",false Satya Microsoft Access External Data 1 17th Jul 2004 10:17 AM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:19 AM.