0
votes

I am trying to print something to a text file while slide show is active in Power Point.

When i run my sub from the vba window, the text file is created and i can print whatever i want, but when i click to the linked shape to run the macro in slide show mode nothing is written to the file. It's like the code doesn't work in slide show mode. How can i fix this? My code is the following.

Sub print2file()
    Set currentSlide = Application.ActiveWindow.View.Slide
        slideIndex = currentSlide.slideIndex
        Open "results.txt" For Append As #1
        Print #1, "some_text"
        Print #1, "Slide Index: "; slideIndex;
        Close #1
End Sub
1

1 Answers

0
votes
Sub print2file()
    ' Dim your variables
    Dim currentSlide As Slide
    
    ' Use SlideShowWindows(1) to get the current view
    Set currentSlide = SlideShowWindows(1).View.Slide
    
        Open "c:\temp\results.txt" For Append As #1
        Print #1, "some_text"
        
        ' no real need for a second variable to hold the slide index
        ' no harm in adding it back, if you prefer
        ' forcing the SlideIndex --> string
        Print #1, "Slide Index: " & CStr(currentSlide.SlideIndex)
        
        Close #1
End Sub