Solved

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

Posted on 2010-09-01
3
540 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

744 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

11 Experts available now in Live!

Get 1:1 Help Now