Ask a questionAsk a question
 

Answerconverting a file from .mht to either .csv or excel

  • Wednesday, October 28, 2009 7:32 PMlslmustang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 byJeff ShanMSFTFriday, October 30, 2009 1:28 AMvba question (From:Visual Basic General)
    •  

Answers

  • Tuesday, November 03, 2009 7:52 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.

All Replies

  • Tuesday, November 03, 2009 7:52 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.