VBA code to generate Multiple XML files

Can someone help me with a VB for generating multiple XML files using data in excel.

Top Contributor Asked on February 2, 2017 in VBA: Programming.
Add Comment
2 Answer(s)

Hi, Could you please provide more details on your question . Thanks!

Expert Answered on February 2, 2017.

I am using this code to create an XML file, I would like to create multiple XML files with different names and data in them. 

However I have the first name and Last Name in two different cells of the sheet (C10 & C11), when I add the reference of “C11”, it throws up an error, need help on this

 

Option Explicit
Private Sub CommandButton1_Click()
Dim iCntr
Dim strFile_Path As String
Dim Filename As String
‘Change cell reference accordingly
Filename = Sheets(“Sheet1”).Range(“C8”)
strFile_Path = “C:\Temp\Test\” & Filename & _
Format(Now(), “dd-MMM-yyyy h-m-s”) & “.xml”
Open strFile_Path For Output As #1
For iCntr = 2 To 111
Print #1, Sheets(“Sheet1”).Range(“D” & iCntr)
Next iCntr
Close #1
End Sub

 

on February 2, 2017.
Add Comment

Hi,

Here is the solution to generate multiple XML files using VBA code.

 

Private Sub CommandButton1_Click()
Dim iCntr
Dim strFile_Path As String
Dim Filename As String
Dim rngFilePaths As Range
'Change Range reference accordingly for file names
Set rngFilePaths = Sheets("Input_Auto").Range("C1:C10")
For Each cell In rngFilePaths
Filename = cell.Value
strFile_Path = "C:\Temp\" & Filename & " " &  Format(Now(), "dd-MMM-yyyy h-m-s") & ".xml"
Open strFile_Path For Output As #1
For iCntr = 2 To 11
Print #1, Sheets("Sheet1").Range("D" & iCntr)
Next iCntr
Close #1
Next
End Sub

 

Screenshots:

Here are the sample input & output screen shots for your reference.

Input:

Generate multiple XML file names rangeGenerate multiple XML file names range

Output:

Generate multiple XML files outputGenerate multiple XML files output

Hope it clarifies your query.

Regards!

 

 

 

 

Expert Answered on February 4, 2017.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.