I have this vba script (see line below with --->) that publishes your workbook to a single file web page (*.mht). I had problems with the Activeworkbook.PublishObjects command below a little bit. My first question is why wouldn't "ActiveWorkBook.PublishObjects(1)" work instead? 2nd question is where does the "_7235" come from at the end of my file name? I found it by manually performing the action and recording it as a macro and using it at the end like you see there to get the script to work. My feeling is that number may change but when and how often? Can't I assign that number as a variant to a string and use it if it does change? Kind of lost in this part of my code. Thanks in advance
Private Sub CommandButton1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
fn = Replace(ActiveWorkbook.Name, ".", "-")
fn = Replace(fn, "-xls", ".xls")
savefn = fn
bfn = fs.getbasename(fn)
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:=fn, _
fileFilter:="Single File Web Page (*.mht), *.mhtl", _
Title:="Publish as Single File Web Page")
If fileSaveName <> False Then
Range("Print_Area").Select
With ActiveWorkbook
With .WebOptions
.RelyOnCSS = False
.RelyOnVML = False
End With
---> With ActiveWorkbook.PublishObjects("Infrastructure Alternative Solution Cost Comparison Tool v5.7_7235")
.Filename = fileSaveName
.HtmlType = xlHtmlStatic
.Publish (True)
.AutoRepublish = False
End With
End With
Range("a1").Select
End If
End Sub
Private Sub CommandButton1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
fn = Replace(ActiveWorkbook.Name, ".", "-")
fn = Replace(fn, "-xls", ".xls")
savefn = fn
bfn = fs.getbasename(fn)
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:=fn, _
fileFilter:="Single File Web Page (*.mht), *.mhtl", _
Title:="Publish as Single File Web Page")
If fileSaveName <> False Then
Range("Print_Area").Select
With ActiveWorkbook
With .WebOptions
.RelyOnCSS = False
.RelyOnVML = False
End With
---> With ActiveWorkbook.PublishObjects("Infrastructure Alternative Solution Cost Comparison Tool v5.7_7235")
.Filename = fileSaveName
.HtmlType = xlHtmlStatic
.Publish (True)
.AutoRepublish = False
End With
End With
Range("a1").Select
End If
End Sub