Class PublishObject (Excel VBA)

The class PublishObject represents an item in a workbook that has been saved to a webpage and can be refreshed according to values specified by the properties and methods of the PublishObject object.

The main procedures of class PublishObject are Delete, PublishObjects.Add and PublishObjects.Delete

Set

To use a PublishObject class variable it first needs to be instantiated, for example

Dim pblobj as PublishObject
Set pblobj = ActiveWorkbook.PublishObjects(Index:=1)

The following procedures can be used to set variables of type PublishObject: PublishObjects.Item, PublishObjects.Add and Workbook.PublishObjects

For Each

Here is an example of processing the PublishObject items in a collection.

blnChartFound = False 
For Each objPO In Workbooks(1).PublishObjects 
 If objPO.SourceType = xlSourceChart Then 
 strFirstPO = objPO.Source 
 blnChartFound = True 
 Exit For 
 End If 
Next objPO

Methods

These are the main methods of the PublishObject class

Delete - Deletes the object.

ActiveWorkbook.PublishObjects(1).Delete

PublishObjects.Add - Creates an object that represents an item in a document saved to a webpage. Such objects facilitate subsequent updates to the webpage while automated changes are being made to the document in Microsoft Excel. Returns a PublishObject object.

With ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceRange, _ 
    Filename:="\\Server\Stockreport.htm", Sheet:="First Quarter", Source:="$G$3:$H$6", _ 
    HtmlType:=xlHtmlStatic, DivID:="Book1_4170") 
        .Publish (True) 
        .AutoRepublish = False 
End With

PublishObjects.Delete - Deletes the object.

ActiveWorkbook.PublishObjects.Delete

Other Methods

Publish - Saves an item or a collection of items in a document to a webpage.

PublishObjects.Publish - Saves a copy of the item or items in the spreadsheet that have been added to the PublishObjects collection to a webpage.

Properties

AutoRepublish when a workbook is saved, Microsoft Excel determines if any item in the PublishObjects collection has the AutoRepublish property set to True, and if so, republishes it. The default value is False.

DivID returns the unique identifier used for identifying an HTML

tag on a webpage. The tag is associated with an item in a document that you have saved to a webpage. An item can be an entire workbook, a worksheet, a selected print range, an AutoFilter range, a range of cells, a chart, a PivotTable report, or a query table.

Filename returns or sets the URL (on the intranet or the web) or the path (local or network) to the location where the specified source object was saved.

HtmlType returns or sets the type of HTML generated by Microsoft Excel when you save the specified item to a webpage. Can be one of the XlHtmlType constants specifying whether the item is static or interactive on the webpage. The default value is xlHtmlStatic.

Parent returns the parent object for the specified object. Read-only.

Sheet returns the sheet name for the specified PublishObject object.

Source returns a value that represents the unique name that identifies items that have a SourceType property value of xlSourceRange, xlSourceChart, xlSourcePrintArea, xlSourceAutoFilter, xlSourcePivotTable, or xlSourceQuery.

SourceType returns an XlSourceType value that represents the type of item being published.

Title returns or sets the title of the webpage when the document is saved as a webpage.

PublishObjects.Count returns a Long value that represents the number of objects in the collection.

PublishObjects.Item returns a single PublishObject object from the collection.

PublishObjects.Parent returns the parent object for the specified object. Read-only.