Solved

Open html file with excel2010 and save as excel2010 file.

Posted on 2014-11-25
11
176 Views
Last Modified: 2014-11-26
If I download an html page and save it, I can open it in excel. If I then save it as an Excel file, I can read the table values into an Access table.

I need VBA to

Open the html file e.g. SACA.html from C:\SAQA_info\ using EXCEL (via Access) and then save it as C:\SAQA_info\SACA.xlsx
and close it.

Will you help please?
0
Comment
Question by:Fritz Paul
  • 6
  • 4
11 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464375
can  you upload SACA.html?

try something like this

dim xlObj as object
set xlObj=createobject("excel.application")
      xlObj.workbooks.open "<path to html>"

     xlObj.activeworkbook.save as "<aaaa.xlsx>"
     xlObj.quit
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 40464379
Hi,

pls try

Sub Macro()

 Dim oExcel As Object
    Dim oBook As Object
    Dim oSheet As Object
    
    strPath = "C:\SAQA_info\"
    strFileNoExt = "SACA"
    
    Set oExcel = CreateObject("Excel.Application")

    Set oBook = oExcel.Workbooks.Open(strPath & strFileNoExt & ".html")
    oExcel.Visible = True

    oBook.SaveAs (strPath & strFileNoExt & ".xlsx")
    oBook.Close False
    
    oExcel.Quit


End Sub

Open in new window

Regards
0
 

Author Comment

by:Fritz Paul
ID: 40464502
I have tried Rgonzo's code, but the html file is not opening.
When I open it manually  there is a load error on which I click on OK and it opens. I think that may be the proble.
I attach a zip file with a directory which I have on my C drive. The html file is also in there.
I also have a simple database with one form with one button to execute the code. The database opens on this form.
Please unzip and see if you can help.
SAQA-Info.html
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:Fritz Paul
ID: 40464505
Sorry I see the zip file did not attach. I will attach the sample database.
0
 

Author Comment

by:Fritz Paul
ID: 40464519
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 40464583
if your file is C:\SAQA_info\SAQA-Info.html

then try

 Sub Macro()

 Dim oExcel As Object
    Dim oBook As Object
    Dim oSheet As Object
    
    strFile1 = "C:\SAQA_info\SAQA-Info.html"
    strFile2 = "C:\SAQA_info\SACA.xlsx"
    
    Set oExcel = CreateObject("Excel.Application")

    Set oBook = oExcel.Workbooks.Open(strFile1)
    oExcel.Visible = True

    oBook.SaveAs (strFile2)
    oBook.Close False
    
    oExcel.Quit


End Sub

Open in new window

0
 

Author Comment

by:Fritz Paul
ID: 40464622
I tried this, but the code still freezes up on this line (It stays in running mode and does not go further in the code)

Set oBook = oExcel.Workbooks.Open(strFile1)

When I open manually it give s an error message like below and I suspect that that is the error message that the VBA does not handle.

Error message
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 40464649
pls give complete path of file
0
 

Author Comment

by:Fritz Paul
ID: 40464701
The path is illustrated below.
It is "C:\SAQA_QUI\SAQA_Info.html"   copied from created shortcut
I attach the file and the database. If you save in "C:\SAQA_QUI\" you have my precise setup.
I use Office proff 2010.

The code that I have on my form is

    Dim oExcel As Object
    Dim oBook As Object
    Dim oSheet As Object
    
    strFile1 = "C:\SAQA_QUI\SAQA_Info.html"
    '           "C:\SAQA_QUI\SAQA_Info.html"   copied from created shortcut
    strFile2 = "C:\SAQA_QUI\SACA.xlsx"
    
    Set oExcel = CreateObject("Excel.Application")

    Set oBook = oExcel.Workbooks.Open(strFile1)
    oExcel.Visible = True

    oBook.SaveAs (strFile2)
    oBook.Close False
    
    oExcel.Quit

Open in new window


Complete Path illustrated
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40466240
Sorry can't help further
0
 

Author Closing Comment

by:Fritz Paul
ID: 40466634
I am so thankful that you tried so hard to help.
Eventually it dawned on me that I should try to supply the "missing" style sheet and now I copy that together with the html file from the internet and save it where Excel is missing it when it opens the html file.
It work s very nice now.
I want to reward you. People may shy away from trying to help if it is a difficult subject.
Thanks again.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

821 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