Solved

open xml file in excel, save to local share as .xls using  MS access VBA

Posted on 2010-09-01
3
542 Views
Last Modified: 2012-05-10
I have an xml file that needs to be read daily.  I need to :

1.  Download http://Server/folder/FMV_20100831.xml
2.  Have it open in excel (opens fine in excel when refrencing the path)
3.  Have it convert and save to \\server\folder\fmv_daily.xls (excel 97-2003 format)

Is this possible?
0
Comment
Question by:MrAutomate
  • 2
3 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33583960
which excel version is installed on the machine?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 33583994
to download file and save it locally use the following function.

taken from http://blog.invisibledenizen.org/2008/11/vba-function-to-download-files.html

usage:

Download_File "http://Server/folder/FMV_20100831.xml", "c:\downloads\FMV_20100831.xml"

***************************************************************

to open xml file in excel, you have 2 options:

Sub Open_XML_File()
Dim oWX As Workbook
Set oWX = Workbooks.OpenXML("c:\downloads\FMV_20100831.xml")
End Sub

Sub Open_XML_File_As_List()
Dim oWX As Workbook
Set oWX = Workbooks.OpenXML(Filename:="c:\downloads\FMV_20100831.xml", LoadOption:=XlXmlLoadOption.xlXmlLoadImportToList)
End Sub

(http://vbadud.blogspot.com/2007/12/open-xml-file-in-excel.html)

***************************************************************
regarding saving the as excel 97-2003 format, you should know that in Excel versions before Excel 2007, code without FileFormat parameter
will not cause too many problems because Excel will use the current FileFormat
of the existing file -- and the default FileFormat for new files is a normal workbook.
however, in Excel 2007-2010 there many file format so you must specify it.
to save it as .xls file in 97-2003 format you should use the following:

 ActiveWorkbook.SaveAs Filename:="\\server\folder\fmv_daily.xls", FileFormat:=xlExcel8
Function Download_File(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
oXMLHTTP.Send 'send request

'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop

oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

'Clear memory
Set oXMLHTTP = Nothing
End Function

Open in new window

0
 

Author Closing Comment

by:MrAutomate
ID: 33612827
Sedgwick - Thanks for the response, it gave me exactly what I needed, and it works great!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My experience with Windows 10 over a one year period and suggestions for smooth operation
Outlook Free & Paid Tools
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now