Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Excel Macro Help

Options
  • 16-06-2009 5:04pm
    #1
    Registered Users Posts: 14,003 ✭✭✭✭


    Hi

    I want to convert all the worksheets in a workbook to single html files. The macro below converts them to xls files, could anyone advise me on how to alter it to save as html.

    Sub ExportToWorkbooks()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim NewBook As Workbook, OldBook As Workbook, sh As Worksheet
    Set OldBook = ActiveWorkbook

    For Each sh In OldBook.Worksheets
    If sh.Visible = xlSheetVisible Then
    sh.Copy
    Set NewBook = Workbooks.Add

    'NewBook.Name = sh.Name & " VALUES.xls"
    NewBook.Sheets(1).Paste
    NewBook.SaveAs Filename:=OldBook.Path & "\" & sh.Name & ".VALUES.xls"
    NewBook.Close
    End If
    Next

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    End Sub


    Thanks


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    ActiveWorkbook.SaveAs Filename:="C:\Users\Book1.htm",  FileFormat:=xlHtml
    

    Something like that should do it, you may have a different version of excel though.


  • Registered Users Posts: 14,003 ✭✭✭✭The Muppet


    I'm using excel 2003

    I'll try that

    Thanks for your help,


  • Registered Users Posts: 14,003 ✭✭✭✭The Muppet


    I modified the filename part of the original macro with the code above but it did not have the desired effect. It did create the html files but there was no data in them , just the macro code.

    Is it possible to combine both macros to create a single macro that will create a html file for each worksheet in my workbook? I am using excel 2003.

    Here is the modified code I used.

    Sub ExportToWorkbooks()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim NewBook As Workbook, OldBook As Workbook, sh As Worksheet
    Set OldBook = ActiveWorkbook

    For Each sh In OldBook.Worksheets
    If sh.Visible = xlSheetVisible Then
    sh.Copy
    Set NewBook = Workbooks.Add

    'NewBook.Name = sh.Name & " VALUES.xls"
    NewBook.Sheets(1).Paste
    NewBook.SaveAs Filename:=OldBook.Path & "\" & sh.Name & ".VALUES.html", FileFormat:=xlHtml
    NewBook.Close
    End If
    Next

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    End Sub


Advertisement