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
0
Utf
3/3/2010 9:15:01 PM
powerpoint 2011 articles. 0 followers. Follow

6 Replies
2985 Views

Similar Articles

[PageSpeed] 10

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" <Edward@discussions.microsoft.com> wrote in message 
news:7CAEDF5E-0C71-443B-9F25-DB163C2739DC@microsoft.com...
> 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 

0
Michael
3/3/2010 9:40:55 PM
=?Utf-8?B?RWR3YXJk?= <Edward@discussions.microsoft.com> wrote in
news:7CAEDF5E-0C71-443B-9F25-DB163C2739DC@microsoft.com: 
> 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... 

0
Matti
3/3/2010 9:43:15 PM
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


0
Karl
3/3/2010 9:45:12 PM
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
> 
> 
> .
> 
0
Utf
3/3/2010 10:44:01 PM
Matti Vuori wrote:
> =?Utf-8?B?RWR3YXJk?= <Edward@discussions.microsoft.com> wrote in
> news:7CAEDF5E-0C71-443B-9F25-DB163C2739DC@microsoft.com: 
>> 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\PowerPoint>copy con temp.pptx
   adsf
   ^Z
           1 file(s) copied.

   D:\Docs\PowerPoint>dir *.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


0
Karl
3/3/2010 11:20:27 PM
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


0
Karl
3/4/2010 2:36:59 AM
Reply:

Similar Artilces:

function keys
This is a multi-part message in MIME format. ------=_NextPart_000_00F7_01CA63A4.2F980A00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I recently upgraded to windows 7. I don't know if this is the problem or what but suddenly I can't use my function number keys. does anyone have a fix for this problem?? thanks, bonnie ------=_NextPart_000_00F7_01CA63A4.2F980A00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4....

Entering array formula using VBA
The following is an array formula.... =IF(OR(G26="",VLOOKUP(G26,$G$16:$H$23,2,FALSE)=0),"",MAX(IF($G$16:G26=G26,$H $16:H26)+1)) 1. Is there a way to enter this into the cell (G26) using VBA (as an array)? 2. If so, if the row that this is to be entered is diff to row 26, how does this get entered into say, G35 and the references changed appropriately? Rob Hi Rob, try this Sub rob() Range("F26").FormulaArray = "=IF(OR(G26="""",VLOOKUP(G26,$G$16:$H$23,2,FALSE)=0),"""",MAX(IF($G$16:G26=G 26,$H$16:H26)+1))" ...

VBA Property showing the link between a shape and a database record
In VBA I want to link a shape to a database and select the record. What are the properties for doing that? Right now I have to do it manually for every shape on my page - I would like to automate that operation. Use the Database Wizard to setup either a document open, refresh event or a right mouse action for the page. "Chuck" <Chuck@nomail.com> wrote in message news:%yVDb.2691$t_2.506@news.get2net.dk... > In VBA I want to link a shape to a database and select the record. What are > the properties for doing that? > > Right now I have to do it manually for every...

VBA
Hi I have this piece of code in my app.... Call searchRange.AdvancedFilter(Action:=xlFilterCopy, CopyToRange:=tempWorksheet.Cells(1, 1), Unique:=True) It seems to duplicate the first item in cells A1 & A2. Any ideas why? Thanks Ben Advanced filter likes to have a row of headers. I'm betting that you don't have one--and your first two rows are the same--so excel sees the first row as headers and the second as data. Ben wrote: > > Hi > I have this piece of code in my app.... > > Call searchRange.AdvancedFilter(Action:=xlFilterCopy, > CopyToRange:=tempWo...

Create and assign an outlook task using VBA?
I have code that creates an Outlook task for me. I want to be able to automatically assign a task to a certain e-mail address recipient. Is this possible? It seems that the right properties are available, but I can't seem to get it to work. Here is my code... Private Sub Create_It_Click() 'Create the Task in Outlook On Error GoTo AddAppt_Err Dim outobj As Outlook.Application Dim outtask As Outlook.TaskItem 'Dim objApptOccur As TaskItem Set outobj = CreateObject("outlook.application") Set outtask = outobj.CreateItem(olTas...

IsIconic function
Hi all, To check whether the window is minimized or not I used function IsIconic. It is OK for almost applications but it has an problem with Excel. In Excel I create two workbooks, each workbook in a separate window. I call IsIconic function and pass the handle of workbook window which is displaying and active to it, the result which this function return is TRUE. This value is wrong because the window is displaying and is active window. Please tell me how to fix this problem. Thanks. I don't have an answer but I can tell you that some more complex software might be doing thing...

vba help
what newsgroup would i use for help with VBA in ms-office apps? i can't find the old SUBSTR function to build strings with. thank you... mike Excel applications? If yes, then there's a .programming newsgroup just waiting for you. But you may want to look at: right, left, mid, instr, instrrev in VBA's help (instrrev was added in xl2k) work wrote: > > what newsgroup would i use for help with VBA in ms-office apps? > i can't find the old SUBSTR function to build strings with. > thank you... > mike -- Dave Peterson ec35720@msn.com Dave Peterson wrote: >...

VBA Inser a new Row
Hi Everyone, Can anyone help me with this query in Excel 2003? Background I have a spreadsheet that keeps track of employee holidays, for example in column “A” I have list of Employee names in column “D” I have the number of holidays that that person is entitled to, Column “E” the number of Holidays taken which is subtracted from “D” and then a few other bits and pieces . Column “N” I have the a date Sun 01/04/2006 that then follows on for 6 months to Sat 30/09/2006 And the underneath that column I have the exact setup with the send half of then year continue from the upper row. I...

Has anyone converted an MS Access VBA project to .Net?
I am looking for any information regarding the conversion of an MS Access VBA project with backend of Oracle to either Visual Basic or VB.Net. Has anyone done any conversion like this and if so, do they have any recommendations, issues to share? Thanks! ...

Slow to Open, Small Workbook <2MB, HTML Paste, VBA procedures
I have a small Excel 2003 workbook 1,300kb that takes 3 to 5 minutes to open. It was created in 2006 and has been opened daily since then. One sheet in the book is overwritten each morning with a paste from a web site. That one sheet has litterly thousands of VBA procedures like the one below (No code just the Sub - end sub). They must be being created automatically from the html paste each morning. Private Sub HTMLHidden999_Click() End Sub I suspect upon open, VBA is inspecting and compiling each sub causing the slow to open problem. 1) Am I correct?...

Missing Graph Functionality
In Office 2003, I used to be able to select the following when formating a data series in a graph: fill effects | shadows This would basically give me shadows on the left/rigt sides, etc. This does not appear to be available in Office 2007. Can I still make this selection? Hi, Are you sure about that selection in 2003. For a column chart the option of a Shadow is available on the Patterns tab. The Fill Effects button displays a dialog with Gradient, Texture, Pattern and Picture. But these are all fill effects and not shadows. Any way in xl2007 you would select the series and then usi...

VBA to Open Hyperlink(Concatenate)
Hello All, I've found useful VBA on this forum for activating my Hyperlink in cell A1 of my Excel spreadsheet : ActiveSheet.Range("A1").Hyperlinks(1).Follow My Hyperlink in Cell A1 is made up of a Concatenate using cells from different worksheets. Such as below : =HYPERLINK((CONCATENATE(HoldPoints!$A$1,HoldPoints!A2),A3) If I click on it, it opens fine, however, if I try to open it with the vba code above, I get an error message "Subscript out of range". I've tried different combinations. It always works by clicking, but not by the vba code. However - If i...

Switch Focus within vba
Having used the FollowHyperlink method to open an html document, from within an Excel vba macro, the focus moves to Intenet Explorer. How can I return the focus from the html document to the Excel spreadsheet from within the vba macro? The code that I am using for the hyperlink is: ActiveWorkbook.FollowHyperlink Address:="Parish Lists.htm", NewWindow:=True TIA Chris ...

Giving Null a value in a VBA stamtement
Hi all, I am writing some VBA code in Access03 in a fields after update event. The field types are decimal (18,1). I am trying to write a SQL statement which looks like this: Docmd.RUNSQL UPDATE tblStorageShip SET tblStorageShip.AmountLeftmg = ([tblStorageShip]![NumberLeftAliquotSize1]*[tblStorageShip]! [SizeUGAliquotSize1])+([tblStorageShip]! [NumberLeftAliquotSize2]*[tblStorageShip]![SizeUGAliquotSize2]); And if one of the fields is a NULL i get a NULL return for that record. Can I somehow set NULL to euqal 0 for this set of code instruction so anytime it wencounters a null while exec...

VBA-code for search,copy and paste
My sheet 1 col A values are unique values.Match sheet names from(sheet2) from these col A values of sheet1 copy that row values(from row2) and paste into the sheet 2 last row ...

Public folders: query regarding the "synchronize now" function
Exchange 2003 SP2 I have a query regarding the "synchronize now" function for public folders. Say I have a public folder called "Bob" with replicas on 3 servers (ServerA, ServerB, ServerC) If I drill down to Folders/Public Folders Select the "BOB" public folder and select the "Status Tab" on say ServerA, I see all 3 replicas listed as expected: If I right click a replica I can select "synchronize now" what does this do exactly? Does it: 1) Push updates out from the replica where you right click and select "synchronize now" ...

Macro to lock VBA project
Hello Is it possible to have a macro that will: 1. under VBA project properties lock project for viewing 2. open input box to input password to view project properties. 3. save file /or prompt to save as. So in other words after you open vba project and play woth macros, work on file etc, one could just click a button and a input box to input password to lock VBA project would be opened. Afeter you input it the input box closes and saves the file or prompts save as if it is not saved yet? I tried to google it and record it but no luck... Anyone? Thank you Excel's VBA doesn't supp...

Excel VBA
So I am fairly new to Visual Basic, but am fluent in C++ and Perl (just so you know some of my background to help me haha) I am am currently trying to write a VB script in excel to fill out approx.700 cover sheets that have been provided for me (i.e. I can't change the location of the cells, or add any more). As of right now, I have about 20 clients that need this done for them. Each client has a csv file with the appropriate data. However, each files contains multiple permits, and each permit needs a coversheet ( as in for each client file, anywhere from 5 to 100 coversheets m...

Embedded Function for a range of answers
I apologize because I know that someone has probably asked this before but I have tried Ecel help and have searched the forum to no avail. I want to create a formula that will give me a specific answer base upon the results of a calculation in another cell. For instance, an this isn't what I want to do, but it is the easiest way to explain it Say that a cell would have a percentage in it, I want the formula fo the next cell to result in a letter grade based upon the percentage i the aformentioned cell. So, say there is an 89% in cell A1, A2 shoul return a "B", but if there is ...

Excel 2003 Power Programming with VBA
Does anyone know the answer to the following questions 1. Why when I use the ISBN for Excel 2003 Power Programming with VBA by J Walkenbach the result comes up with Excel X Power Programming with VBA? Are they the same book? Why is the latter cheaper 2. Does Microsoft intend to release a 2003 version of Excel 2002 Visual Basic for Applications Step by Step by R Jacobson? Is there any point waiting for the former version No idea - how are you "using" the ISBN? When I enter 0-7645-4072-6, which I got from John's web site, into Barnes & Noble's search engine it com...

Lookup/match function
With these functions they find the highest value which is less than or equal to the lookup value. For example A B 1 30 2 60 3 70 4 80 5 100 If I want the lookup the 'A' value of 66 it will return '2'. I want to lookup the highest value ie anything over 60 return value of 3. Anybody have any ideas ? Simon -- spgprivate ------------------------------------------------------------------------ spgprivate's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=35862 View this thread: http://www.excelforum.com/showthread.ph...

Incrementing/decrementing column characters using only worksheet functions?
How can I increment and decrement column characters/letters using worksheet functions? I have a list of 5 characters corresponding to columns. The first character might be A, for column 1. How can I get the second character in the list to automatically configure itself to be B, the third C, the fourth D and the fifth E? That is, I want to set this up so that the second character is linked to the first, the third to the second and so on. That way if I change the first character from A to D then the second character in the list will automatically become E, the third will change to F, the f...

"Save As" function issues
Every time I try to use the "Save As" function in Microsoft Word, my PC tries to open a completely unrelated program (AutoManager WorkFlow 6.1 - by Cyco software). I am running Microsoft Office Word 2007 (12.0.6504.5000) SP2 MSO (12.0.6514.5000) on Windows Vista Enterprise (Service Pack 2). Is this most likely an issue with the settings in Microsoft Word, or in the AutoManager Workflow program? Are you accessing Save As with a keyboard shortcut (presumably one you assigned to it)? If so, it may be being overridden by a different assignment to that combination in Windo...

No data event function
Hello. I have many reports and am trying to use a function to display a message when there is no data in the report: "Report has no data." The function seems to work in that if there is data, a report runs with the data. However, if there is no data, the report does not run but "Report has no data" does not appear to the user. I'd appreciate suggestions. Public gfReportHasNoData As Boolean Public Function PrintPreviewReport(pstrReport As String, pfPreview As Boolean, pstrWhere As String) As String 'Comments: Print or preview a report and handle errors 'ps...

Creating a pivot chart in vba?
All, i know nothing about creating Pivot tables and charts, i've only just bothered to start using them. I now have a need to produce pivot charts and suceeded in doing that, my question is how do i refresh the data automatically or should i rebuild the pivot each time using VBA. If automatic refreshing is a simple option i'd go with that but the sheet the table and chart are on will be protected. All advice welcome! -- Simon Lloyd Regards, Simon Lloyd 'Microsoft Office Help' (http://www.thecodecage.com) --------------------------------------------------------------------...