+ Reply to Thread
Results 1 to 10 of 10

SaveAs

Hybrid View

  1. #1
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    SaveAs

    Hi, i am trying to save a range on Sheet1 as a web page. i have managed to save the entire workbook as a webpage but am struggling to get the right syntax for just the range on sheet1. when i do this manually i select the range, set the print area, then choose file-save as web page- and choose selection:print area or republish if i have done this before. i am not sure also where to add the directory i wish to save it to. the file name always changes, so i can either: use the name of the file or i can use the same file name that is entered into a cell (cell never changes). i hope this makes some sort of sense. here is the code i used to save the entire workbook

    myName = This Workbook.Fullname
    myHtmlName = Left(myName,Len(myName)-4)&".htm"
    ThisWorkbook.SaveAs Filename:=myHtmlName:=,FileFormat:=xlHtml
    thanks for any help
    Last edited by slipperyjim; 06-04-2009 at 11:06 PM.

  2. #2
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    any tips? :|

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    re: SaveAs

    Hello Jim, and welcome to the forum.

    When I record the steps to save a range as a web page (html), I get the following code:
    With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
            "C:\Documents and Settings\Paul\Desktop\test.htm", "Sheet1", "$B$4:$C$16", _
            xlHtmlStatic, "Demo2(1)_22030", "")
            .Publish (True)
            .AutoRepublish = False
        End With
    This is in Excel 2007, and I'm not sure if it has changed from 2003. Try recording it and see!

  4. #4
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    Paul, thanks for the reply, i have done this also, however, when it is saved the filename will always change. see if i can better explain what happens.

    Template: person builds the isolation procedure
    when they have finished they click a "workbook save as" macro that
    saves the workbook as an ordinary .xls file with the name being the same
    contents as cell b35...the name in cell b35 could be DYAIES-001 then the
    next time they use the template it could be DYBZES-100

    Svaed As Workbook: After saving as to a directory etc, they then will need to click next
    macro that will save a range as a single web page or whatever.
    again, this is saved as the same name of the workbook or can be
    the contents of cell b35

    i can get the macro for saving the whole book working, just not saving that range from sheet1 as a web page with the name. i will try your code above and see if it will save the name each time it changes

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    re: SaveAs

    To save the file with the value from cell B35, try changing
    "C:\Documents and Settings\Paul\Desktop\test.htm"
    to
    "C:\Documents and Settings\Paul\Desktop\" & Range("B35").Value & ".htm"

  6. #6
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    syntax error when stepping through

    Sub saveaswebpage()
    
    
    
    With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
            "C:\Documents and Settings\Paul\Desktop\" & Range("B35").Value & ".htm"
            xlHtmlStatic, "Demo2(1)_22030", "")
            .Publish (True)
            .AutoRepublish = False
        End With
    End Sub

  7. #7
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    i do realize i have to change directory also

  8. #8
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    stepping through on the first code worked though

  9. #9
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    re: SaveAs

    ok, scratch that... now i have this code....

    Sub saveaswebpage()
    
    
    
    With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
            "J:\Isolation Data Base\IsolationWebsite\DryMillA\" & Range("B35").Value & ".htm", "Sheet1", "$A$34:$L$67", _
            xlHtmlStatic, "Demo2(1)_22030", "")
            .Publish (True)
            .AutoRepublish = False
        End With
    End Sub
    runtime error at .publish (true) line

  10. #10
    Registered User
    Join Date
    06-04-2009
    Location
    australia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Re: SaveAs

    nevermind i got it

    many thanks for your help, it really is greatly appreciated...the final code is...

    Sub saveaswebpage()
    
    
    
    With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
            "J:\Isolation Data Base\IsolationWebsite\DryMillA\" & Range("D21").Value & ".htm", "Sheet1", "$A$34:$L$67", _
            xlHtmlStatic, "Demo2(1)_22030", "")
            .Publish
            .AutoRepublish = False
        End With
    End Sub

+ 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