PPT2000: Word Tables That Are Changed in VBA Lose Changes When Double-Clicked (277559)



The information in this article applies to:

  • Microsoft PowerPoint 2000

This article was previously published under Q277559

SYMPTOMS

When you use Microsoft Visual Basic for Applications (VBA) code to modify a Microsoft Word table that is inside a Microsoft PowerPoint presentation, the modifications are lost the next time that you double-click the Word table.

CAUSE

This behavior occurs when you use VBA to modify a Word table, and then save and close the presentation. The next time that you manually edit the Word table, the modifications that you made programmatically are lost.

When you manually edit an OLE object, such as a Word table, PowerPoint and Word pass data back and forth. If you click outside the editing window of the Word table, Word provides a preview image of the changes that you made, and then PowerPoint issues a Save command, to save the changes.

However, when you automate these same steps by using code, PowerPoint does not issue a command to save the OLE object (the Word table). Word still displays an updated image of the Word table, which makes it appear that you have successfully edited the table.

If you then save, close, and reopen the presentation, the Word table loses its modifications.

RESOLUTION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
To resolve this issue, you must issue a Save command in your VBA code to save the changes to your Word table, as in the following sample macro.

NOTE: To use any of the code samples contained in this article, you must add a reference to Microsoft Word 2000 in the Visual Basic Editor.
  1. Press ALT+F11 to open the Visual Basic Editor. On the Tools menu, click References.
  2. Scroll down to the Microsoft Word 9.0 Object Library check box in the list of references, and click to select the check box if it is not already selected.
  3. Click OK.

Sample Macro

Sub ClearCells()
   Dim oSlide As Slide
   Dim oShape As Shape
   Dim oDoc As Word.Document
   Dim oTable As Word.Table
   Dim oCell As Word.Cell
   Dim lCol As Long
   Dim lRow As Long
   Dim lColCount As Long
   Dim lRowCount As Long

   '
   ' Loop through the presentation, checking each slide.
   '
   For Each oSlide In ActivePresentation.Slides

      With oSlide
   '
   ' Loop through each shape on the slide.
   '
         For Each oShape In .Shapes
   '
   ' Test to see if the shape contains an embedded OLE
   ' object.
   '
            If oShape.Type = msoEmbeddedOLEObject Then
   '
   ' If it does, is it a Word Document object?
   '
               If oShape.OLEFormat.ProgID = "Word.Document.8" Then
   '
   ' Set oDoc egual to the object.
   '
                  Set oDoc = oShape.OLEFormat.Object
   '
   ' This assumes that there is only one table in the object.
   ' If there is only one table, continue.
   '
                  If oDoc.Tables.Count = 1 Then
   '
   ' Set oTable to the first table in the object.
   '
                     Set oTable = oDoc.Tables(1)
   '
   ' Get the number of columns and rows in the table.
   '
                     lColCount = oTable.Columns.Count
                     lRowCount = oTable.Rows.Count
   '
   ' Loop through the table, starting at row 2, through the
   ' last row in the column with index value of lCol. Then
   ' go to the next column and repeat.
   '
                     For lCol = 1 To lColCount
                        For lRow = 2 To lRowCount
   '
   ' Set oCell to the table cell located at row lRow,
   ' column lCol.
   '
                           Set oCell = oTable.Cell(lRow, lCol)
   '
   ' Select the contents of the cell, and then delete the selection.
   ' Finally, set oCell to Nothing.
   '
                           oCell.Select
                           Selection.Delete
                           Set oCell = Nothing
                        Next lRow
                     Next lCol
   '
   ' Set oTable to Nothing.
   '
                     Set oTable = Nothing
                  End If
   '
   ' Save the object by using the Word Document object method,
   ' Save. This ensures that the changes made will remain.
   ' Then, set oDoc to Nothing.
   '
                  oDoc.Save
                  Set oDoc = Nothing
               End If
            End If
         Next oShape
      End With
   Next oSlide
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbnofix KB277559