Harish Singh Adhikari


Hi,

I am a new learner in Macro field. I want to know how we can open a folder using macro. The scenario is ---> I want to open a folder having a no of files . After that i want to open these files one by one.......





Re: How to open a folder through excel macro!

Peter Mo.


Hi

The easiest way is using Scripting objects ...

Dim fso As Object
Dim fldr As Object
Dim fil As Object

Dim wb As Workbook

strFldrPath = "c:\upload\" ' or whatever the folder path is

Set fso = CreateObject("scripting.filesystemobject")
Set fldr = fso.GetFolder(strFldrPath)

For Each fil In fldr.Files
Set wb = Workbooks.Open(Filename:=fil.Path)

' process file

wb.Close

Next fil


Is this the sort of thing you wanted

Regards

Peter Mo.






Re: How to open a folder through excel macro!

Amps

Hi Peter,

i tried this but its not working. r u sure its working for you

i just need to open a given folder thru excel vba code.

Please help me.

Thanks,

Amps






Re: How to open a folder through excel macro!

Amps

i could get it somehow,

try this, its very simple.

Shell "explorer.exe " & folderpath, vbNormalFocus

Amps





Re: How to open a folder through excel macro!

magicalclick

First reference a library called "Microsoft Scripting Runtime" to fix your compiler error of Object Not Found.

Second, Dim fso as Scripting.FileSystemObject.

Don't copy my code, when you type ".", a list of objects and methods will show up, just select it so there won't be any typo.

The rest, check the documention

http://msdn2.microsoft.com/en-us/library/hww8txat.aspx





Re: How to open a folder through excel macro!

Peter Mo.

Hi

I've obviously missunderstood what you were after. What do you want to do once you've opened the folder

Regards

Peter Mo.