+ Reply to Thread
Results 1 to 2 of 2

Importing xml file to excel and insert the value to the correct column and row

  1. #1
    Registered User
    Join Date
    01-06-2013
    Location
    norway
    MS-Off Ver
    Office 365
    Posts
    49

    Importing xml file to excel and insert the value to the correct column and row

    Hi everybody,
    I am new here so I I'll try posting this and hope someone can help me with this, since i know to little about vba coding.
    I have this excel sheet that I have made with two sheets, one of which is called data and the other input. One contains Data with different posts that have different letters and numbers. In the second sheet called input I have created a button for importing data from an xml file: Excel_project.xlsm

    The Xml file is here: xml.zip


    I want to be able to choose location and any xml file as long as it is of the same type of xml format. When I import from the input sheet and into the data sheet, the quantities must be placed in the correct column and row based on the posts name. This will mean filling in quantities where there are values on the right posts.


    I also add an excel sheet for how I want it to look after the quantities are imported: Excel_project_Imported.xlsm
    I sincerely hope someone can help me with this.

    BR
    TH
    Attached Files Attached Files
    Last edited by trhuus; 03-26-2019 at 02:32 PM.

  2. #2
    Registered User
    Join Date
    01-06-2013
    Location
    norway
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Importing xml file to excel and insert the value to the correct column and row

    Hi,
    I have found this code for importing the xml file, but it doesn't import it to the "Input" sheet. It will make a new sheet called "Original_XML_" (see code) I want it to be imported in the active sheet (Input) and overwrite it the next time I will import a new xml with updated data.

    Here's the code:

    Sub OpenXML()
    Dim FilesToOpen
    Dim x As Integer

    Dim sDelimiter As String
    Dim newSheet As Worksheet

    On Error GoTo ErrHandler
    Application.ScreenUpdating = False

    sDelimiter = ","

    FilesToOpen = Application.GetOpenFilename _
    (FileFilter:="XML Files (*.xml), *.xml", _
    MultiSelect:=True, Title:="XML File to Open")

    If TypeName(FilesToOpen) = "Boolean" Then
    MsgBox "No Files were selected"
    GoTo ExitHandler
    End If

    With ActiveWorkbook
    For x = 1 To UBound(FilesToOpen)
    Set newSheet = .Sheets.Add
    newSheet.Name = "Original_XML_" & x
    Application.DisplayAlerts = False
    .XmlImport URL:= _
    FilesToOpen(x), ImportMap:=Nothing, _
    Overwrite:=True, Destination:=newSheet.Range("A1")
    Application.DisplayAlerts = True
    Next x
    End With

    ExitHandler:
    ErrHandler:
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to look up column and row, and insert data into correct cell
    By dancing-shadow in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-27-2016, 04:15 AM
  2. vba code for opening excel file and insert a new column in exisiting excel file
    By saratu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2014, 02:55 PM
  3. Replies: 0
    Last Post: 12-05-2013, 04:57 PM
  4. Replies: 8
    Last Post: 05-08-2012, 11:09 PM
  5. Replies: 0
    Last Post: 04-13-2011, 05:14 PM
  6. Importing a column from 1 file to another
    By davidww in forum Excel General
    Replies: 1
    Last Post: 04-28-2010, 07:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1