Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

809 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