VBA modification to set Default folder and files to select

  • I have code that works perfectly to get properties from folder files. However Code ask me to choose directory manually. Is there any option to change this code that allow me input this directory in the code and input predefined filetypes (currently code picks all folder files and list them, but for example notepad file has no video length that why i need to input filetypes in the code also). I will appreciate any help in this issue. Thank you.


    Code that need modification:


  • Re: VBA modification to set Default folder and files to select


    Hi 7absinth,


    Try this (just change the strMyDir variable to suit):



    Regards,


    Robert

  • Re: VBA modification to set Default folder and files to select


    Hi Robert,


    Seems your modification doesn't work. I copied all your code and modified directory and filetype to mkv and it pops out an error in the row:


    Code
    Cells(lRow, iCol + 1) = .getdetailsof(.items, vArray(iCol))


    Also seems (by looking into the code) it filters only one filetype, but I have mkv avi and mp4 videos and maybe these filetypes will expand with new ones in the future.

  • Re: VBA modification to set Default folder and files to select


    The following will solve the multiple extension issue:



    I haven't used the .GetDetailsOf property so I can't really there I'm afraid. Are you should that method works on the file types you're trying on?


    You might have to stick with selecting the directory via the Application.FileDialog(msoFileDialogFolderPicker) method.


    Robert

  • Re: VBA modification to set Default folder and files to select


    I have tried something similar to this but it found same error:
    Cells(lRow, iCol + 1) = .getdetailsof(.items, vArray(iCol))


    I suppose the same that I need to use Application.FileDialog(msoFileDialogFolderPicker) but it is not I am looking for and I am still trying to resolve this.

  • Re: VBA modification to set Default folder and files to select


    Try this (again just change the strDirectory variable to suit):



    Regards,


    Robert

  • Re: VBA modification to set Default folder and files to select


    Now it show me only headers (name and lenght). Even after I commented the row:
    ' varMyFileExtns = Array(".mkv", ".avi", ".mp4")


    Seems it doesnt go further than headers, but code executed.

  • Re: VBA modification to set Default folder and files to select


    The extensions need to be in the array without the period . just like I had them.


    Quote

    Seems it doesn't go further than headers, but code executed.


    No sure as it worked for me :confused:


    I take it that there are mkv, avi or mp4 file types in the desired directory? If so manually check (i.e. right-click on a file via Windows Explorer) on one of them and ensure their properties have been filled out.


    Barring that I'm out of ideas I'm afraid.


    Robert

  • Re: VBA modification to set Default folder and files to select


    I have tried with many other directories and code executes same. All file have these extensions in the properties. How it comes that my first code I added in this post worked and extracted all folder files including mentioned video file types but now it doesn't find any folder included files?

  • Re: VBA modification to set Default folder and files to select


    Please do not requote entire posts as it just creates clutter on the server. Just quote specific lines to support your case. Thanks.


    I cannot offer you any more advice I'm afraid as it worked for me albeit I only tried it on avi files. I've shown you how to run the code for specific file types so just incorporate that into your original code (so yes you will still have to point to the relevant directory each time).


    Good luck with it.


    Robert

  • Re: VBA modification to set Default folder and files to select


    I finally found why it doesnt work for me. Your file extension is visible with file name. Right? But my extension is not visible unless I dont open file properties with right mouse where extension is shown. When I added manually ".avi" behind the filename its worked. But how to execute this code if extension is not visible and all it show me is file name?


    I have added the picture.


    [ATTACH=CONFIG]69014[/ATTACH]

  • Re: VBA modification to set Default folder and files to select


    Yes, without the extension my code won't work. Though I would set the property in Windows (plenty of references of how to do that on the Internet) so file extensions are visible you can try and filter the files based on their 'Item type' which is their second property (just as their length is the 27th property). I've coded the following to use item type to filter for avi and mkv files. You will have to add the other desired item types to the varMyItemTypes array once you determine what they are and don't forget to change the strDirectory variable to suit:



    Robert

  • Re: VBA modification to set Default folder and files to select


    Interesting approach. But most important part its FINALLY works.:yourock: Only you forgot to remove this line:


    'MsgBox objFolder.GetDetailsOf(varFileName, 2)


    I hope others will notice this line too. :) Thank a lot Robert you did a great job. Well done.:wowee:


    I also added line under Next varFileName to autofit columns.
    Cells.Columns.AutoFit

  • Re: VBA modification to set Default folder and files to select


    Hi 7absinth,


    Thanks for the kind words and I'm glad we were finally able to get it working :)


    For ease of use, I have made the changes you mention in my code above.


    Regards,


    Robert

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!