locked
converting a file from .mht to either .csv or excel RRS feed

  • Question

  • I'm a DBA and need some help on getting started with this task. I think I need to use an office object but really have no idea. Someono told me it should easy yet I've searched around for some code hints for converting files and have found nothing...
    Any help or links to some code snippets that might help would be greatly appreciated!

    Thanks!
    • Moved by Jeff Shan Friday, October 30, 2009 1:28 AM vba question (From:Visual Basic General)
    Wednesday, October 28, 2009 7:32 PM

Answers

  • Hello,

    If you manually convert a .mht into a Excel format in Excel UI and record a macro you'll get following VBA code:

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
        Workbooks.Open Filename:="C:\Users\xxxx\Documents\ExcelOpenMHT.mht"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Users\v-timli\Documents\ExcelOpenMHT.xlsx", FileFormat:=xlOpenXMLWorkbook _
            , CreateBackup:=False
    End Sub

    Therefore, you have to get a Excel installed in your computer, if you want the convertion completed within the Excel you only need to modify above code.
    If you need to perform the same task outside Excel in your own application you need to add reference to Excel Object Library in your project in Visual Studio.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Thursday, November 5, 2009 3:24 AM
    Tuesday, November 3, 2009 7:52 AM

All replies

  • Hello,

    If you manually convert a .mht into a Excel format in Excel UI and record a macro you'll get following VBA code:

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
        Workbooks.Open Filename:="C:\Users\xxxx\Documents\ExcelOpenMHT.mht"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Users\v-timli\Documents\ExcelOpenMHT.xlsx", FileFormat:=xlOpenXMLWorkbook _
            , CreateBackup:=False
    End Sub

    Therefore, you have to get a Excel installed in your computer, if you want the convertion completed within the Excel you only need to modify above code.
    If you need to perform the same task outside Excel in your own application you need to add reference to Excel Object Library in your project in Visual Studio.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Thursday, November 5, 2009 3:24 AM
    Tuesday, November 3, 2009 7:52 AM
  • One way to open an MHT file and convert it into EXCEL or appropriate app on a PC seems to be:
    1) Find the MHT file that you want to convert and right click on it.
    2) Open with Internet Explorer. Open sub-files until you have opened the one with the data you want.
    3) Copy the sub-file.
    4) Paste into an email and send it to yourself.

    5) Open the email and copy and paste it onto the desk top or into the right app on your PC.
    6) For EXCEL, you may need to paste the data first into WORD and then format it with tabs so that the info appears in columns or is "tab delimited".
    7) Then copy and paste it into EXCEL.


    • Edited by JGD4MMY Tuesday, May 21, 2013 8:52 PM
    Tuesday, May 21, 2013 8:51 PM