Home | VBA Section | General Section | Downloads | Licensing | Privacy Policy | OfficeTips RSS Feed

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 <VariableName> with the variable who value you wish to retrieve assuming that
  <VariableName> 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.


' --------------------------------------------------------------------------------
' Copyright ©1999-2009, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------


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-2009 Shyam Pillai. All rights reserved.