We import an XML file (changes daily, and up to 5 per night) by right clicking, import, XML and it imports the single column or data we need.
I have written VBA code doing everything I need to do, import to a certain cell, continue or stop based on a pop-up question, and a printout later on.
But the import of the XML file imports 26 columns worth of data. I would like to isolate the barcode value or one column's worth of data.
Here is the code I have at the moment:
Option Explicit
Sub Biotinidase_Auto_Import_Print()
Dim AnswerYes As String
Dim AnswerNo As String
Dim strTargetFile As String
Dim wb As Workbook
'Plate 1
Application.Goto (ActiveWorkbook.Sheets("Panthera File 1").Range("B2"))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strTargetFile = Application.GetOpenFilename
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Panthera File 1").Range("B2")
wb.Close False
Application.ScreenUpdating = True
AnswerYes = MsgBox("Do you want to import more plates?", vbQuestion + vbYesNo, "User Repsonse")
If AnswerYes = vbYes Then
'Plate 2
Application.Goto (ActiveWorkbook.Sheets("Panthera File 2").Range("B2"))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strTargetFile = Application.GetOpenFilename
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Panthera File 2").Range("B2")
wb.Close False
Application.ScreenUpdating = True
AnswerYes = MsgBox("Do you want to import more plates?", vbQuestion + vbYesNo, "User Repsonse")
If AnswerYes = vbYes Then
'Plate 3
Application.Goto (ActiveWorkbook.Sheets("Panthera File 3").Range("B2"))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strTargetFile = Application.GetOpenFilename
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Panthera File 3").Range("B2")
wb.Close False
Application.ScreenUpdating = True
AnswerYes = MsgBox("Do you want to import more plates?", vbQuestion + vbYesNo, "User Repsonse")
If AnswerYes = vbYes Then
'Plate 4
Application.Goto (ActiveWorkbook.Sheets("Panthera File 4").Range("B2"))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strTargetFile = Application.GetOpenFilename
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Panthera File 4").Range("B2")
wb.Close False
Application.ScreenUpdating = True
AnswerYes = MsgBox("Do you import more plates?", vbQuestion + vbYesNo, "User Repsonse")
If AnswerYes = vbYes Then
'Plate 5
Application.Goto (ActiveWorkbook.Sheets("Panthera File 5").Range("B2"))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strTargetFile = Application.GetOpenFilename
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Panthera File 5").Range("B2")
wb.Close False
Application.ScreenUpdating = True
ThisWorkbook.PrintOut From:=16, To:=20 'Print Plate Maps 1 - 5
Else
ThisWorkbook.PrintOut From:=16, To:=19 'Print Plate Maps 1 - 4
End If
Else
ThisWorkbook.PrintOut From:=16, To:=18 'Print Plate Maps 1 - 3
End If
Else
ThisWorkbook.PrintOut From:=16, To:=17 'Print Plate Maps 1 & 2
End If
Else
ThisWorkbook.PrintOut From:=16, To:=16 'Print Plate Map 1
End If
End Sub
The beginning part of the XML file
<?xml version="1.0" encoding="utf-8"?>
<Plate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AnalyteName>BT</AnalyteName>
<TraversalOrder>
<OrderIndex>Rows</OrderIndex>
</TraversalOrder>
<PlateMapName>BT:1</PlateMapName>
<Barcode>
<Orientation>Vertical</Orientation>
<Code>BT00001</Code>
<CodeType>Code128</CodeType>
<ErrorDescription />
</Barcode>
<PlateTypeName>ThermoCliniplate</PlateTypeName>
<Wells>
<Well>
<Index>0</Index>
<SampleBarcode>2022000009</SampleBarcode>
<WellType>
<Type>Patient</Type>
<Level>0</Level>
</WellType>
<IsBad>false</IsBad>
<RequestedDisksPerWell>1</RequestedDisksPerWell>
<PunchedDisksPerWell>1</PunchedDisksPerWell>
</Well>
<Well>
<Index>1</Index>
<SampleBarcode>2022000000</SampleBarcode>
<WellType>
<Type>Patient</Type>
<Level>0</Level>
</WellType>
<IsBad>false</IsBad>
<RequestedDisksPerWell>1</RequestedDisksPerWell>
<PunchedDisksPerWell>1</PunchedDisksPerWell>
</Well>
The data I need to import in the column is the barcode number
EX:
2022000009
or in the XML file
<SampleBarcode>2022000009</SampleBarcode>
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)by changing the load option to popup with the XML Schema menu when importing, but this would be to complicated for my coworkers.