0

I was wondering if someone could help me with a PowerPoint VBA issue that I have encountered. I have a system of two PowerPoint presentations that I have linked dynamically and interactively using VBA, and which open using an external VBS script in the same folder which plays the PowerPoints in presentation mode and resizes and positions them on the screen. The VBS script links to this sub which automatically runs the other linked subs:

Sub Open_Presentation_VEdit()

Dim Ret
Dim Ret2

Dim PPT1 As Object
Set PPT1 = CreateObject("PowerPoint.Application")

Dim PPT2 As Object
Set PPT2 = CreateObject("PowerPoint.Application")

Dim filePath As String
filePath = ActivePresentation.Path

Ret = IsWorkBookOpen(filePath & "\Stand Up Title Page - With Macros.pptm")
Ret2 = IsWorkBookOpen(filePath & "\Stand Up Summary and Breakdowns - With Macros.pptm")

If Ret = True And Ret2 = False Then

Set PPT1 = Presentations("Stand Up Title Page - With Macros.pptm")
Set PPT2 = Presentations.Open(filePath & "\Stand Up Summary and Breakdowns - With Macros.pptm")

Call TaskbarAutohideOn
Call Resize_Presentations

Else: MsgBox "Close all stand-up wall slides"
End If

End Sub

The problem I am having is that a function that I have, IsWorkBookOpen, is creating problems for allowing multiple users to the system:

Function IsWorkBookOpen(fileName As String)
    Dim ff As Long, ErrNo As Long

    On Error Resume Next
    ff = FreeFile()
    Open fileName For Input Lock Read As #ff
    Close ff
    ErrNo = Err
    On Error GoTo 0

    Select Case ErrNo
    Case 0:    IsWorkBookOpen = False
    Case 70:   IsWorkBookOpen = True
    Case Else: Error ErrNo
    End Select
End Function

I have this function written in because I was having problems with the opening sequence if someone pressed the script multiple times, lots of versions of the two PowerPoints tried to open which caused issues with the code and errors.

However, the system needs to be opened by multiple people at once, who are accessing this over a network. Is it possible to write a function that can tell if an individual user has the two presentations open? I.e. allow only one copy of each presentation to be open at one time by an individual user, but allow multiple users.

Thanks in advance for any help!

Holly Mae
  • 31
  • 4
  • First, PowerPoint is a single-instance application; you can't create two different application objects (though various bugs sometimes make it possible to do by accident with unhappy results). Next, you first set PPT1 (and 2) to instances of PowerPoint, then later set them to Presentation objects. You should be dimming new variables to hold the presentation objects. I'd make those changes then check back. – Steve Rindsberg Jul 29 '20 at 15:36
  • Thanks! How do I call both presentations if I can't create two applications for them? Do them in seperate subs? – Holly Mae Jul 30 '20 at 16:02
  • You can open multiple presentations in one instance of the application. Dim oPres1 as Object : Set oPres1 = PPT1.Presentations.Open(etc) or Set oPres1 = PPT1.Presentations("presentation name") – Steve Rindsberg Jul 30 '20 at 17:04
  • I don't understand sorry, that would only call one presentation no? – Holly Mae Jul 31 '20 at 08:32
  • Yes. That was the example for one presentation. Create two object variables, use the same code twice, once for each variable, to open two presentations. – Steve Rindsberg Aug 01 '20 at 00:24
  • I changed it to do this and now I am getting an error saying "the object invoked has disconnected from its clients" – Holly Mae Aug 03 '20 at 12:53
  • I think it's time to edit your original post, post the code *as it currently stands* and tell us on what line the error occurs. – Steve Rindsberg Aug 03 '20 at 15:04
  • Well all I changed was what you told me to, changed it back when it caused the above error. If you have any suggestions about how to structure it, it would be apprieciated. – Holly Mae Aug 04 '20 at 11:09
  • I'm sorry, but unless we can see the code that produces the error, we can't help fix it. Please edit your post and include the current version of the code as requested. Thanks. – Steve Rindsberg Aug 04 '20 at 17:34

0 Answers0