OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

Inter-presentation communication using a function

It's possible to retrieve a variable value from one presentation into another active presentation by creating a public function in a code module in the presentation from which you wish to retrieve the value. Follow the steps given below. In the same manner it is also possible to retrieve object references.

 

1. Create a function in the parent presentation that returns the value of the variable.     Replace with the variable who value you wish to retrieve assuming that   is a public variable for the purposes of this example. 

    Function GetVarValue()
        GetVarValue=<VariableName>
    End Function

2. Invoke that function from the hyperlinked presentation and it will return the value.

    MsgBox Application.Run("C:\Path\presentation1.ppt!module1.GetVarValue")

 

Inter-presentation communication using custom document properties 

Yet another approach is to store the value that is required between presentations in a custom document property which is updated whenever the value changes. This property can then be read from any presentation. The benefit of this approach is the variable value can be saved between sessions for later retrieval even in the main presentation itself.



1. Create a routine in the main presentation which writes the variable value into the document property whenever required.

Sub UpdateProperty(Index As Integer)
    On Error Resume Next
    With ActivePresentation.CustomDocumentProperties
        .Item(Index:="LastUsedIndex").Delete
        .Add Name:="LastUsedIndex", LinkToContent:=msoFalse, _
             Type:=msoPropertyTypeNumber, Value:=Index
    End With
End Sub

2. Use the following function in the 2nd presentation which retrieves for the document property value from 1st presentation. It accepts two arguments - a reference to a presentation and the property to be retrieved from that presentation.

Function GetDocPropertyValue(oPres As Presentation, PropertyName As String)
On Error Resume Next
GetDocPropertyValue = oPres.CustomDocumentProperties(PropertyName)
End Function

 


Copyright 1999-2014 (c) Shyam Pillai. All rights reserved.