VBA

Moderators: PavlinII
Number of threads: 1614
Number of posts: 3000

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problems with ActiveWorkbook.XmlImport & ImportMap Posted by netwerkingnut on 28 Nov 2012 at 3:36 PM
I've been working on a script that auto-creates a new *.xlsx workbook, imports the XSD map, and imports an XML file. I've just about worked out the bugs to have it use the new file and format the data as needed, then it filters out data based on vendor (I have a list of 52 vendors - and this part works beautifully), dumps the mined data to a new workbook, saves, closes, and continues.

The problem I'm having is the map does not auto-import. It fails to import the map and data.
Sub openxmlfile()
    Workbooks.Add
    ActiveWorkbook.XmlMaps.Add("\\Automation files\VendorDetails.xsd" _
        , "vendordetails").Name = "vendordetails_Map"
    ActiveWorkbook.XmlImport = ("\\VendPaymtDtl_12112621482978.xml")
End Sub
Public Sub VendorRecon()
'
'   This section prepares the yyyy Mmm - Vendor Recon File.xlsx
'
    Call openxmlfile
    Call borders
    Call SSN
    Call USD
    Call dates
    Call FName
    Call LName
    Call freeze
    Call rename_worksheet
    Call save
'
'   This section begins the creation of each vendor's *.xlsx recon file
'
    Call vendor_001
    Call copy
    Call create_new
    Call paste
    Call fit_hide
    Call page_format
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = ""
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .LeftFooter = "(001) Ada County"
    End With
    Application.PrintCommunication = True
    Call page_fit
    Sheets("Sheet1").Select
    Sheets("Sheet1").Name = "2012 Dec - (001) Vendor Recon"
    Call freeze
    ChDir "Y:\2012 Dec\Vendor Recon Files\My Recon Files"
    ActiveWorkbook.SaveAs Filename:= _
        "Y:\2012 Dec\Vendor Recon Files\My Recon Files\2012 Dec - (001) Vendor Recon File.xlsx" _
        , FileFormat:=51, Password:="x", WriteResPassword:="x", CreateBackup:=False
    Call close_window
'
    Call vendor_040
    .
    .
    .
End Sub


Here's my XSD Map:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:sql="urn:schemas-microsoft-com:mapping-schema" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
  <xs:complexType name="PremiumReconType" >
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="vendordetails" type="dateheader" />
      <xs:element minOccurs="0" maxOccurs="unbounded" name="payment" type="paymentmade" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="dateheader" >
    <xs:attribute name="datetime" type="xs:date" />
  </xs:complexType>
  <xs:complexType name="paymentmade" >
    <xs:attribute name="run_date" type="xs:date" />
    <xs:attribute name="payroll_cycle" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="pay_eff_date" type="xs:date" />
    <xs:attribute name="vendor_name" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
	</xs:attribute>  
    <xs:attribute name="address_lines" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
	</xs:attribute>  
    <xs:attribute name="vendor_city_state_zip" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
	</xs:attribute>  
    <xs:attribute name="country" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
	</xs:attribute>  
    <xs:attribute name="ssn" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="11" />
          <xs:maxLength value="11" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
	  <xs:attribute name="FirstName" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="MiddleName" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="0" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="LastName" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="50" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="employer_num" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="4" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="vendor_code" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="10" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="status" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="20" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="ongoing" type="xs:decimal" />
    <xs:attribute name="adjustment" type="xs:decimal" />
    <xs:attribute name="funding_code" >
      <xs:simpleType>
        <xs:restriction base="xs:int">
          <xs:totalDigits value="4" />
          <xs:fractionDigits value="0" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="plan_name" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="plan_number" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="policy_number" >
      <xs:simpleType>
        <xs:restriction base="xs:string" >
          <xs:minLength value="1" />
          <xs:maxLength value="30" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
	</xs:complexType>
  <xs:element name="vendordetails" type="PremiumReconType" />
</xs:schema>




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.