If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
VBA Dir () function
Hi every one,
I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? Thanks for help. -- Best regards, Edward |
#2
|
|||
|
|||
VBA Dir () function
I believe that is by default. because you used *.ppt it will return all
files where the file extension begins with ppt. -- Michael Koerner MS MVP - PowerPoint "Edward" wrote in message ... Hi every one, I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? Thanks for help. -- Best regards, Edward |
#3
|
|||
|
|||
VBA Dir () function
=?Utf-8?B?RWR3YXJk?= wrote in
: Hi every one, I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? This is surprising. Have you checked how your code works with other suffixes, for example does "*.do" also return .doc files? If it does, your version of VBA (and/or Windows) has a bug. But if you have Office version 2007 or later, this could as well be a deliberate kludge to get PPT macros to list all PowerPoint files. Or it could be just a random bug in your macro, triggered by the phase of the moon or day of the month... You ask if you are missing something. One thing is this: being ready for _anything_ when writing Office macros! No matter how the code works, don't be surprised, don't get upset, just work around it. This one is easy to handle. Just add a check for what was returned: if myfile "" then if lcase(right(myfile, 4)) = ".pptx" then ... or something similar... |
#4
|
|||
|
|||
VBA Dir () function
Edward wrote:
Hi every one, I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") Okay, first off, use & to concatenate strings, rather than +. It'll save you grief down the road. but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? Yeah, you'll find the same thing happens if you drop to a command window. There's some ancient plumbing at work in Windows, from back in the day when 3 chars was the max for extensions. You really always need to post-process Dir results, to be sure they are what you expect. For example, if you use a ".*" extension, you'll also get directories! -- ..NET: It's About Trust! http://vfred.mvps.org |
#5
|
|||
|
|||
VBA Dir () function
Thanks. Now that I'm sure it wasn't from my side , I can go ahead and remove
*.potx files. By the way if you use myfile=Dir(file pathe\+"*.pptx") it will only return pptx file and not ppt files . However I think this is an ugly defect in Dir() function, and MS should fix this. Best regards, Edward "Karl E. Peterson" wrote: Edward wrote: Hi every one, I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") Okay, first off, use & to concatenate strings, rather than +. It'll save you grief down the road. but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? Yeah, you'll find the same thing happens if you drop to a command window. There's some ancient plumbing at work in Windows, from back in the day when 3 chars was the max for extensions. You really always need to post-process Dir results, to be sure they are what you expect. For example, if you use a ".*" extension, you'll also get directories! -- ..NET: It's About Trust! http://vfred.mvps.org . |
#6
|
|||
|
|||
VBA Dir () function
Matti Vuori wrote:
=?Utf-8?B?RWR3YXJk?= wrote in : Hi every one, I use the following code to find and populate a combobox with *.ppt files myfile=Dir(file pathe\+"*.ppt") but this return not only *.ppt file but also *.pptx file ! Anything I'm missing here? This is surprising. Have you checked how your code works with other suffixes, for example does "*.do" also return .doc files? If it does, your version of VBA (and/or Windows) has a bug. No, it's just the way Windows has been, ever since Win95. Actually, NT 3.5x probably acted this way too, but I'm too lazy to test. Try this: D:\Docs\PowerPointcopy con temp.pptx adsf ^Z 1 file(s) copied. D:\Docs\PowerPointdir *.ppt Volume in drive D has no label. Volume Serial Number is FA0F-40AB Directory of D:\Docs\PowerPoint 02/23/2010 03:36 PM 82,432 CitizenCommunications.ppt 08/01/2000 08:28 AM 25,600 pptEvent.ppt 03/03/2010 03:17 PM 6 temp.pptx 3 File(s) 108,038 bytes 0 Dir(s) 739,961,786,368 bytes free D:\Docs\PowerPoint (I had to actually create a file with the PPTX extension, as I don't use that version. That's why it's so small.) Anyway, you see, this is just the way Windows works. Basically, if you hand it a 3-character extension, it appends an asterisk to it. -- ..NET: It's About Trust! http://vfred.mvps.org |
#7
|
|||
|
|||
VBA Dir () function
Edward wrote:
By the way if you use myfile=Dir(file pathe\+"*.pptx") it will only return pptx file and not ppt files . Right. That's the essential algorithm, near as I can tell. Windows only appends the undesired asterisk when you hand it a 3-character extension. However I think this is an ugly defect in Dir() function, and MS should fix this. The defect is actually in the FindFirstFile and FindNextFile API functions. -- ..NET: It's About Trust! http://vfred.mvps.org |
Thread Tools | |
Display Modes | |
|
|