PDA

View Full Version : How to open multiple XMLS at one time



VinoBob
02-14-2010, 07:42 PM
Hi!

I would like to open all XML files in a specific directory. I would like the directory to be selectable with a dialog. How could i do this?

lucas
02-16-2010, 06:53 PM
File-open?

I don't mean to be a smart*** but why re-invent the wheel. Is there further logic that you didn't convey?

VinoBob
02-17-2010, 01:27 PM
I dont know man. If you got any solution for this its ok. I just want to work on all of the xmls located in a specific directory, namelly changing values of strings, without any user intervention. Only the dicertory should be selected, not the xmls one by one.

fumei
02-17-2010, 01:50 PM
Ummm, VinoBob, could you please clarify what it is you are asking for exactly?

"If you got any solution for this "

The solution is to use File > Open.

"I just want to work on all of the xmls located in a specific directory, namelly changing values of strings, without any user intervention. Only the dicertory should be selected, not the xmls one by one."

This is inconsistent.

A) "work on all of the xmls located in a specific directory"

B) "Only the dicertory should be selected, not the xmls one by one."


Only the directory should be selected? Ok, then you want to know nothing about processing ANY files (never mind xml). In that case...why even mention them?

Try asking questions for what you actually want. If all you want to ask about is getting a specific folder via dialog...then who cares if the files you want to process are xml, doc, xls, txt mp3, dll.....

Do you know what folder you want to process from? If you do, then use the Dir function.

The reason I ask is, again, there is sort of an inconsistency.

A) "specific directory"
B) "I would like the directory to be selectable"

If the specific folder is known, processing any explicit files (.xml...whatever) is very easy. The Dir function. If it is not known, and you want to browse for it....then ask that.

lucas
02-17-2010, 01:57 PM
Maybe something like this:


Function PickFolder(strStartDir As Variant) As String
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", _
16 + 32 + 64, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function

Sub ExampleTest()
MsgBox PickFolder("c:\")
End Sub


Sub GetUserFolder()
Dim strTheirPick As String
strTheirPick = PickFolder("c:\")
' do whatever with the folder name
' they selected - make a new folder...whatever
End Sub

lucas
02-17-2010, 01:58 PM
a word example using the same code

fumei
02-17-2010, 02:05 PM
Darn...I was just about to post the exact same code.

lucas
02-17-2010, 02:13 PM
I yoinked it from you a long time ago Gerry.....it's handy.

fumei
02-17-2010, 02:15 PM
An a possible alternative to getting the selected folder as a string. That means YOU have to decide what the heck you are going to do with it...which you have not stated.

Function FindFolder() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.ButtonName = "OK"
.Title = "Select Parent Folder"
If .Show = 0 Then Exit Sub
FindFolder = .SelectedItems(1)
End With
End Function


For example, IF you really do want to process all - let's make it easy - .doc files in a given folder, but you do NOT know which folder (it has to be selectable), then:
Function FindFolder() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.ButtonName = "OK"
.Title = "Select Parent Folder"
If .Show = 0 Then Exit Sub
FindFolder = .SelectedItems(1)
End With
End Function


Sub ProcessAllDocs()
Dim file
Dim path As String
If FindFolder <> "" Then ' a folder WAS selected
path = FindFolder & "\"
' adding the path separator is VERY VERY important!
file = Dir(path & "*.doc")
Do While file <> ""
Documents.Open Filename:= path & file
' do whatever it is with each file
ActiveDocument.Save
ActiveDocument.Close
file = Dir()
Loop
End If
End Sub
All .doc files would be processed in the folder selected with FindFolder.

Please try and be clear and precise when you are asking things. It makes it much easier. In fact, I have absolutely no idea if the above is remotely close to what you are trying to do.