importing XML files

D

deepaj87

Hi!

Firstly, is there a macro to go through many subfolders and change the
extension of all the files? Or if I do that myself,
Is there a way to somehow get a macro to seek the XML files, if
they're all in groups separated by folders?
So, have the macro get the 1st file (using an XML map), edit it using
another macro, save and close, then go get the next folder?

I have a series of groups of XML files, all following the same XML Map
in Excel, and I want a macro to bring them in, group by group, saving
them as separate files.

Thanks!
 
J

Joel

Sub getxml()

Const myfolder As String = "c:\temp"

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(myfolder)

If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders

If sf.Files.Count > 0 Then
For Each file In sf.Files
If UCase(Right(file, 3)) = "XML" Then

'add code to open each file here.

End If

Next file
End If

Next sf
End If

End Sub
 
D

deepaj87

Sub getxml()

Const myfolder As String = "c:\temp"

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(myfolder)

If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders

If sf.Files.Count > 0 Then
For Each file In sf.Files
If UCase(Right(file, 3)) = "XML" Then

'add code to open each file here.

End If

Next file
End If

Next sf
End If

End Sub








- Show quoted text -

Thank you so much! When I try to implement that though, it says that
the 'path is not found' although I put the path where the files are
where it was written c:/temp. The path I put is where all the
subfolders are. What am I doing wrong?
 
D

deepaj87

Thank you so much! When I try to implement that though, it says that
the 'path is not found' although I put the path where the files are
where it was written c:/temp. The path I put is where all the
subfolders are. What am I doing wrong?- Hide quoted text -

- Show quoted text -

Ok, never mind, I figured that one what, but I'm still having trouble
figuring out the code to open the individual files, because the
extension first has to be changed, and it should only import the XMLs
according to the map I setup. Do have any idea on how to do this?
 
J

Joel

The only time I get your error is if a put in a bad path or the path includes
a filename. It fails on the line

Set folder = _
fso.GetFolder(myfolder)

Make sure you are only putting in the path name without any file name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top