Solved

Open html file with excel2010 and save as excel2010 file.

Posted on 2014-11-25
11
162 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 119

Expert Comment

by:Rey Obrero
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
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
Comment Utility
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
 

Author Comment

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

Author Comment

by:Fritz Paul
Comment Utility
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
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
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
pls give complete path of file
0
 

Author Comment

by:Fritz Paul
Comment Utility
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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Sorry can't help further
0
 

Author Closing Comment

by:Fritz Paul
Comment Utility
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

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

743 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

14 Experts available now in Live!

Get 1:1 Help Now