+ Reply to Thread
Results 1 to 6 of 6

macro for save as from .xls to .mthml

Hybrid View

  1. #1
    Registered User
    Join Date
    10-07-2011
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    54

    macro for save as from .xls to .mthml

    I would like to create a click button on Userform that allows user to do "save as" the data sheet with certain cells and in .mhtml format.

    I have tried code shown below but it's not working. please if anybody could help for this. Thanks.

    Public Sub SaveAs()
    Const PATH As String = "c:\"
    With ActiveWorkbook
    'Range of the cells that I want to export
    Range("K12:K3054").Select
    .SaveAs FileName:=PATH & _
    'file name and type of file
    .Sheets("Sheet1").Range("A1").Value & ".mthml"
    End With
    End Sub
    Last edited by copythat; 10-30-2011 at 02:15 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: macro for save as from .xls to .mthml

    SaveAs is a method of Workbook an Worksheet, but not Range. You cannot save a range as a file.

    Also, Excel does not provide native support for MHTML. You can specify a format of HTML.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-07-2011
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: macro for save as from .xls to .mthml

    6StringJazzer, thank you very much

  4. #4
    Registered User
    Join Date
    10-07-2011
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: macro for save as from .xls to .mthml

    I would like to ask a little bit more. Now I try a new code (shown below) to export the file as .html. My problem is the data is not exported properly. Web browser can't read it and I need the export file to contain formatting and colors as shown in excel. If it's possible?

    Sub Button1_Click()
    Const PATH As String = "c:\"
    With ActiveWorkbook
    .SaveAs Filename:=PATH & _
    .Sheets("sheet1").Range("AE3").Value & ".html"
    End With
    End Sub
    Last edited by copythat; 10-29-2011 at 08:45 PM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro for save as from .xls to .mthml

    It would serve you to record yourself doing an actual SAVEAS HTML and then work with adapting the resulting code. Saving to HTML is an entirely different syntax.

    Sub Button1_Click()
    Dim fName As String, fPath As String
    
    fPath = "C:\"
    fName = Sheets("Sheet1").Range("AE3").Value
    
        With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _
            fPath & fName & ".html", _
            ActiveSheet, "", xlHtmlStatic, fName, fName)
            .Publish (True)
            .AutoRepublish = False
        End With
    End Sub
    That should get you started experimenting with the various parameters.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    10-07-2011
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: macro for save as from .xls to .mthml

    Thank you very much!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1