Avatar of Fritz Paul
Fritz Paul
Flag for South Africa asked on

Open html file with excel2010 and save as excel2010 file.

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?
Microsoft Access

Avatar of undefined
Last Comment
Fritz Paul

8/22/2022 - Mon
Rey Obrero (Capricorn1)

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
Rgonzo1971

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
Fritz Paul

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
Fritz Paul

ASKER
Sorry I see the zip file did not attach. I will attach the sample database.
Fritz Paul

ASKER
Rgonzo1971

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Fritz Paul

ASKER
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
Rgonzo1971

pls give complete path of file
Fritz Paul

ASKER
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Fritz Paul

ASKER
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.