read datas from XML to excel using VBAmacros

  • Thread starter Thread starter born2achieve
  • Start date Start date
B

born2achieve

hi, i am newbie to this environment.i have one button in my ExcelWorkbook.i
have sample.xml in my "c:\" i want to read that sample.xml and disply in my
Excel Workbook if i click the button using VBA macro programing.please can
any one show some exmple to do this please
 
born2achieve said:
hi, i am newbie to this environment.i have one button in my
ExcelWorkbook.i
have sample.xml in my "c:\" i want to read that sample.xml and disply in
my
Excel Workbook if i click the button using VBA macro programing.please
can
any one show some exmple to do this please


A Button event to open the xml-file looks like this:

Public Sub OpenXML()
Workbooks.Open ("C:\sample.xml")
End Sub

This way the file will be opened in a new Excel window.
All you have to do is copy and paste the xml-data if you want it to be
displayed in a workbook that's already open.
 
DEar Friend,
i have tried this, but i cooldnot do this please help me to do this please
code:

Dim eMessage As String
Dim xlApp As Excel.Application

'AppActivate("Microsoft Excel")
'xlApp = GetObject(, "Excel.Application")
xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.OpenXML("C:\sample .xml")

ChDir("C:\")
xlApp.AlertBeforeOverwriting = False
xlApp.DisplayAlerts = False
xlApp.ActiveWorkbook.SaveAs(Filename:="C:\sample .xls")
xlApp.AlertBeforeOverwriting = True
xlApp.DisplayAlerts = True

If Not xlApp Is Nothing Then
xlApp.Quit()
xlApp = Nothing

End If
 
born2achieve said:
DEar Friend,
i have tried this, but i cooldnot do this please help me to do this
please
code:

Dim eMessage As String
Dim xlApp As Excel.Application

'AppActivate("Microsoft Excel")
'xlApp = GetObject(, "Excel.Application")
xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.OpenXML("C:\sample .xml")

ChDir("C:\")
xlApp.AlertBeforeOverwriting = False
xlApp.DisplayAlerts = False
xlApp.ActiveWorkbook.SaveAs(Filename:="C:\sample .xls")
xlApp.AlertBeforeOverwriting = True
xlApp.DisplayAlerts = True

If Not xlApp Is Nothing Then
xlApp.Quit()
xlApp = Nothing

End If

You are working with so called 'objects' and you can not assign a value to
an object by saying i.e.
xlApp = CreateObject("Excel.Application")

Instead you should use Set, so for all objects it should be:

Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")

....and in the end also:

Set xlApp = Nothing


Please try that and let me know what happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top