VBA to get Excel data and produce XML file

navagos4

New Member
Joined
Jan 15, 2019
Messages
2
Can you help me on the below?

I have 2 tables in Excel. (images)

2mrxjqc.png


14xo28i.png


I want these tables to be exported in XML in a certain format (see code below).

Code:
<?xml version="1.0" encoding="UTF-8"?>
<cbc:CBC_OECD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stf="urn:oecd:ties:stf:v4"
	xmlns:cbc="urn:oecd:ties:cbc:v1" xmlns:iso="urn:oecd:ties:isocbctypes:v1" version="String"
	xsi:schemaLocation="urn:oecd:ties:cbc:v1 CbcXML_v1.0.1.xsd">
	<cbc:MessageSpec>
		<cbc:SendingEntityIN>BNP7589635</cbc:SendingEntityIN>
		<cbc:TransmittingCountry>BE</cbc:TransmittingCountry>
		<cbc:ReceivingCountry>ES</cbc:ReceivingCountry>
		<cbc:MessageType>CBC</cbc:MessageType>
		<cbc:Language>EN</cbc:Language>
		<cbc:Warning>Warning message</cbc:Warning>
		<cbc:Contact>Contract information</cbc:Contact>
		<cbc:MessageRefId>BE2016ES20170310093047</cbc:MessageRefId>
		<cbc:MessageTypeIndic>CBC401</cbc:MessageTypeIndic>
		<cbc:ReportingPeriod>2015-12-31</cbc:ReportingPeriod>
		<cbc:Timestamp>2016-10-20T09:30:47</cbc:Timestamp>
	</cbc:MessageSpec>
	<cbc:CbcBody>
		<cbc:ReportingEntity>
			<cbc:Entity>
				<cbc:ResCountryCode>BE</cbc:ResCountryCode>
				<cbc:TIN issuedBy="BE">00000051T</cbc:TIN>
				<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589635</cbc:IN>
				<cbc:Name>Company</cbc:Name>
				<cbc:Address legalAddressType="OECD301">
					<cbc:CountryCode>BE</cbc:CountryCode>
					<cbc:AddressFix>
						<cbc:Street>Avenue Jean Dubrucq</cbc:Street>
						<cbc:BuildingIdentifier>5</cbc:BuildingIdentifier>
						<cbc:PostCode>1080</cbc:PostCode>
						<cbc:City>Molenbeek-Saint-Jean</cbc:City>
					</cbc:AddressFix>
				</cbc:Address>
			</cbc:Entity>
			<cbc:ReportingRole>CBC701</cbc:ReportingRole>
			<cbc:DocSpec>
				<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
				<stf:DocRefId>BE2015-994845658</stf:DocRefId>
			</cbc:DocSpec>
		</cbc:ReportingEntity>
		<cbc:CbcReports>
			<cbc:DocSpec>
				<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
				<stf:DocRefId>BE2015-458698518</stf:DocRefId>
			</cbc:DocSpec>
			<cbc:ResCountryCode>ES</cbc:ResCountryCode>
			<cbc:Summary>
				<cbc:Revenues>
					<cbc:Unrelated currCode="EUR">2000000</cbc:Unrelated>
					<cbc:Related currCode="EUR">3000000</cbc:Related>
					<cbc:Total currCode="EUR">5000000</cbc:Total>
				</cbc:Revenues>
				<cbc:ProfitOrLoss currCode="EUR">500000</cbc:ProfitOrLoss>
				<cbc:TaxPaid currCode="EUR">1000000</cbc:TaxPaid>
				<cbc:TaxAccrued currCode="EUR">650000</cbc:TaxAccrued>
				<cbc:Capital currCode="EUR">15000000</cbc:Capital>
				<cbc:Earnings currCode="EUR">7500000</cbc:Earnings>
				<cbc:NbEmployees>35</cbc:NbEmployees>
				<cbc:Assets currCode="EUR">10000000</cbc:Assets>
			</cbc:Summary>
			<cbc:ConstEntities>
				<cbc:ConstEntity>
					<cbc:ResCountryCode>ES</cbc:ResCountryCode>
					<cbc:TIN issuedBy="BE">00000059T</cbc:TIN>
					<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589444</cbc:IN>
					<cbc:Name>Empresa</cbc:Name>
					<cbc:Address legalAddressType="OECD301">
						<cbc:CountryCode>ES</cbc:CountryCode>
						<cbc:AddressFree>Avenida de San Luis 12-13, 28033 Madrid</cbc:AddressFree>
					</cbc:Address>
				</cbc:ConstEntity>
				<cbc:IncorpCountryCode>FR</cbc:IncorpCountryCode>
				<cbc:BizActivities>CBC504</cbc:BizActivities>
				<cbc:OtherEntityInfo>Other information</cbc:OtherEntityInfo>
			</cbc:ConstEntities>
			<cbc:ConstEntities>
				<cbc:ConstEntity>
					<cbc:ResCountryCode>ES</cbc:ResCountryCode>
					<cbc:TIN issuedBy="BE">00000061T</cbc:TIN>
					<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589511</cbc:IN>
					<cbc:Name>Entidad</cbc:Name>
					<cbc:Address legalAddressType="OECD301">
						<cbc:CountryCode>ES</cbc:CountryCode>
						<cbc:AddressFree>Pas de Sota Muralla 100-110, 08003 Barcelona</cbc:AddressFree>
					</cbc:Address>
				</cbc:ConstEntity>
				<cbc:IncorpCountryCode>FR</cbc:IncorpCountryCode>
				<cbc:BizActivities>CBC501</cbc:BizActivities>
				<cbc:OtherEntityInfo>Other information</cbc:OtherEntityInfo>
			</cbc:ConstEntities>
		</cbc:CbcReports>
		<cbc:AdditionalInfo>
			<cbc:DocSpec>
				<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
				<stf:DocRefId>BE2015-492824825</stf:DocRefId>
			</cbc:DocSpec>
			<cbc:OtherInfo>Other information</cbc:OtherInfo>
			<cbc:ResCountryCode>ES</cbc:ResCountryCode>
			<cbc:SummaryRef>CBC601</cbc:SummaryRef>
		</cbc:AdditionalInfo>
	</cbc:CbcBody>
</cbc:CBC_OECD>

There are also 3 XML Schema files that will validate the main XML file. I don't know how to attach them herewith, sorry!

Thank you,
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
sorry the above code of XML should be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<cbc:CBC_OECD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stf="urn:oecd:ties:stf:v4"
xmlns:cbc="urn:oecd:ties:cbc:v1" xmlns:iso="urn:oecd:ties:isocbctypes:v1" version="String"
xsi:schemaLocation="urn:oecd:ties:cbc:v1 CbcXML_v1.0.1.xsd">
<cbc:MessageSpec>
<cbc:SendingEntityIN>BNP7589635</cbc:SendingEntityIN>
<cbc:TransmittingCountry>BE</cbc:TransmittingCountry>
<cbc:ReceivingCountry>ES</cbc:ReceivingCountry>
<cbc:MessageType>CBC</cbc:MessageType>
<cbc:Language>EN</cbc:Language>
<cbc:Warning>Warning message</cbc:Warning>
<cbc:Contact>Contract information</cbc:Contact>
<cbc:MessageRefId>BE2016ES20170310093047</cbc:MessageRefId>
<cbc:MessageTypeIndic>CBC401</cbc:MessageTypeIndic>
<cbc:ReportingPeriod>2015-12-31</cbc:ReportingPeriod>
<cbc:Timestamp>2016-10-20T09:30:47</cbc:Timestamp>
</cbc:MessageSpec>
<cbc:CbcBody>
<cbc:ReportingEntity>
<cbc:Entity>
<cbc:ResCountryCode>BE</cbc:ResCountryCode>
<cbc:TIN issuedBy="BE">00000051T</cbc:TIN>
<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589635</cbc:IN>
<cbc:Name>Company</cbc:Name>
<cbc:Address legalAddressType="OECD301">
<cbc:CountryCode>BE</cbc:CountryCode>
<cbc:AddressFix>
<cbc:Street>Avenue Jean Dubrucq</cbc:Street>
<cbc:BuildingIdentifier>5</cbc:BuildingIdentifier>
<cbc:PostCode>1080</cbc:PostCode>
<cbc:City>Molenbeek-Saint-Jean</cbc:City>
</cbc:AddressFix>
</cbc:Address>
</cbc:Entity>
<cbc:ReportingRole>CBC701</cbc:ReportingRole>
<cbc:DocSpec>
<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
<stf:DocRefId>BE2015-994845658</stf:DocRefId>
</cbc:DocSpec>
</cbc:ReportingEntity>
<cbc:CbcReports>
<cbc:DocSpec>
<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
<stf:DocRefId>BE2015-458698518</stf:DocRefId>
</cbc:DocSpec>
<cbc:ResCountryCode>ES</cbc:ResCountryCode>
<cbc:Summary>
<cbc:Revenues>
<cbc:Unrelated currCode="EUR">2000000</cbc:Unrelated>
<cbc:Related currCode="EUR">3000000</cbc:Related>
<cbc:Total currCode="EUR">5000000</cbc:Total>
</cbc:Revenues>
<cbc:ProfitOrLoss currCode="EUR">500000</cbc:ProfitOrLoss>
<cbc:TaxPaid currCode="EUR">1000000</cbc:TaxPaid>
<cbc:TaxAccrued currCode="EUR">650000</cbc:TaxAccrued>
<cbc:Capital currCode="EUR">15000000</cbc:Capital>
<cbc:Earnings currCode="EUR">7500000</cbc:Earnings>
<cbc:NbEmployees>35</cbc:NbEmployees>
<cbc:Assets currCode="EUR">10000000</cbc:Assets>
</cbc:Summary>
<cbc:ConstEntities>
<cbc:ConstEntity>
<cbc:ResCountryCode>ES</cbc:ResCountryCode>
<cbc:TIN issuedBy="BE">00000059T</cbc:TIN>
<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589444</cbc:IN>
<cbc:Name>Empresa</cbc:Name>
<cbc:Address legalAddressType="OECD301">
<cbc:CountryCode>ES</cbc:CountryCode>
<cbc:AddressFree>Avenida de San Luis 12-13, 28033 Madrid</cbc:AddressFree>
</cbc:Address>
</cbc:ConstEntity>
<cbc:IncorpCountryCode>FR</cbc:IncorpCountryCode>
<cbc:BizActivities>CBC504</cbc:BizActivities>
<cbc:OtherEntityInfo>Other information</cbc:OtherEntityInfo>
</cbc:ConstEntities>
<cbc:ConstEntities>
<cbc:ConstEntity>
<cbc:ResCountryCode>ES</cbc:ResCountryCode>
<cbc:TIN issuedBy="BE">00000061T</cbc:TIN>
<cbc:IN issuedBy="BE" INType="Identification Number type">BNP7589511</cbc:IN>
<cbc:Name>Entidad</cbc:Name>
<cbc:Address legalAddressType="OECD301">
<cbc:CountryCode>ES</cbc:CountryCode>
<cbc:AddressFree>Pas de Sota Muralla 100-110, 08003 Barcelona</cbc:AddressFree>
</cbc:Address>
</cbc:ConstEntity>
<cbc:IncorpCountryCode>FR</cbc:IncorpCountryCode>
<cbc:BizActivities>CBC501</cbc:BizActivities>
<cbc:OtherEntityInfo>Other information</cbc:OtherEntityInfo>
</cbc:ConstEntities>
</cbc:CbcReports>
<cbc:AdditionalInfo>
<cbc:DocSpec>
<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
<stf:DocRefId>BE2015-492824825</stf:DocRefId>
</cbc:DocSpec>
<cbc:OtherInfo>Other information</cbc:OtherInfo>
<cbc:ResCountryCode>ES</cbc:ResCountryCode>
<cbc:SummaryRef>CBC601</cbc:SummaryRef>
</cbc:AdditionalInfo>
</cbc:CbcBody>
</cbc:CBC_OECD>
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top