D
Don Kline
I have to select and import files all day long with an XML extension. Two
files are imported for each case.
The file names are paired with one file ending with "OUT.XML" and its
companion file ends with "INI.XML".
What I want to do is when the end user gets to the point of selecting the
*OUT.XML that it only shows the files ending in *OUT.XML. The code is set up
to automatically pick up the INI file. Yet when I get to the point at which
the macro displays the list of available files, I see both files - the
OUT.XML and the INI.XML. How can I limit the selection to the *OUT.XML".
Sub ImportXMLFile()
Set wbMain = ThisWorkbook
Set wsInputs = wbMain.Worksheets("GUI")
Set wsXMLSource = wbMain.Worksheets("XMLSource")
Set wsColumnParse = wbMain.Worksheets("ColumnParse")
Set wsXMLINI = wbMain.Worksheets("XMLINI")
strRelayOutSourceDir = wsInputs.Range("D22")
ChDirNet strRelayOutSourceDir
strFilter = "XML files (*out.xml), *out.xml"
strCaption = "Select an XML File"
strSelectedFile = Application.GetOpenFilename(strFilter, , strCaption)
Application.DisplayAlerts = False
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Importing OUT.XML file"
'open selected workbook for the XMLSource
Workbooks.OpenXML Filename:=strSelectedFile, LoadOption:= _
xlXmlLoadImportToList
Set wbXMLSource = ActiveWorkbook
Cells.Select
'pick up the values for the XMLSource tab
Selection.Copy
Application.DisplayAlerts = False
wbMain.Activate
wsXMLSource.Activate
Cells.PasteSpecial xlPasteValues
wbXMLSource.Close (False)
Set wbXMLSource = Nothing
'now pick up the INI values
Application.StatusBar = "Importing INI file"
strSelectedFile = Left(strSelectedFile, Len(strSelectedFile) - 7)
strSelectedFile = strSelectedFile + "INI.XML"
Workbooks.OpenXML Filename:=strSelectedFile, LoadOption:= _
xlXmlLoadImportToList
Set wbXMLINI = ActiveWorkbook
Cells.Select
Selection.Copy
wsXMLINI.Activate
Cells.PasteSpecial xlPasteValues
wbXMLINI.Close (False)
Set wsXMLINI = Nothing
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
wsInputs.Activate
Range("B3").Select
'close created objects
' Set wsXMLINI = Nothing
Set wsColumnParse = Nothing
Set wsInputs = Nothing
Set wbMain = Nothing
End Sub
files are imported for each case.
The file names are paired with one file ending with "OUT.XML" and its
companion file ends with "INI.XML".
What I want to do is when the end user gets to the point of selecting the
*OUT.XML that it only shows the files ending in *OUT.XML. The code is set up
to automatically pick up the INI file. Yet when I get to the point at which
the macro displays the list of available files, I see both files - the
OUT.XML and the INI.XML. How can I limit the selection to the *OUT.XML".
Sub ImportXMLFile()
Set wbMain = ThisWorkbook
Set wsInputs = wbMain.Worksheets("GUI")
Set wsXMLSource = wbMain.Worksheets("XMLSource")
Set wsColumnParse = wbMain.Worksheets("ColumnParse")
Set wsXMLINI = wbMain.Worksheets("XMLINI")
strRelayOutSourceDir = wsInputs.Range("D22")
ChDirNet strRelayOutSourceDir
strFilter = "XML files (*out.xml), *out.xml"
strCaption = "Select an XML File"
strSelectedFile = Application.GetOpenFilename(strFilter, , strCaption)
Application.DisplayAlerts = False
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Importing OUT.XML file"
'open selected workbook for the XMLSource
Workbooks.OpenXML Filename:=strSelectedFile, LoadOption:= _
xlXmlLoadImportToList
Set wbXMLSource = ActiveWorkbook
Cells.Select
'pick up the values for the XMLSource tab
Selection.Copy
Application.DisplayAlerts = False
wbMain.Activate
wsXMLSource.Activate
Cells.PasteSpecial xlPasteValues
wbXMLSource.Close (False)
Set wbXMLSource = Nothing
'now pick up the INI values
Application.StatusBar = "Importing INI file"
strSelectedFile = Left(strSelectedFile, Len(strSelectedFile) - 7)
strSelectedFile = strSelectedFile + "INI.XML"
Workbooks.OpenXML Filename:=strSelectedFile, LoadOption:= _
xlXmlLoadImportToList
Set wbXMLINI = ActiveWorkbook
Cells.Select
Selection.Copy
wsXMLINI.Activate
Cells.PasteSpecial xlPasteValues
wbXMLINI.Close (False)
Set wsXMLINI = Nothing
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
wsInputs.Activate
Range("B3").Select
'close created objects
' Set wsXMLINI = Nothing
Set wsColumnParse = Nothing
Set wsInputs = Nothing
Set wbMain = Nothing
End Sub