Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

785 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