PDA

View Full Version : ppt: switch between two open ppt presentations (documents are variable names)



smakatura
08-07-2023, 05:17 AM
I have two sheets ("000-macros for report.pptm" and "slides 07-25-23.pptx")

my goal is to


start on slides sheet

save slides sheet name as startfilename (variable)


switch to macro sheet

save macro sheet name as macrodocument (variable)


switch back to codes sheet

this codes sheet name can be different name each time. that is why I saved it as startfilename



I tried to just include relevant code




Dim StartPres As Presentation
Dim macrodocument As String
Dim StartFileName As String
Set StartPres = ActivePresentation
StartFileName = ActivePresentation.Name 'startfilename is now set to "slides 07-25-23.pptx"
Presentations("000-macros for report").Windows(1).Activate
macrodocument = sld.Shapes("Macro Doc Value").TextFrame.TextRange.Text ' macrodocument is not set to "000-macros for report.pptm"
Presentations(StartFileName).Windows(1).Activate 'this is where the issue is

genevievelyl
09-28-2023, 12:01 AM
Hello, I think instead of relying on the ActivePresentation object, you can directly use the filename of the "slides 07-25-23.pptx" presentation. Here's an updated version of your code:



Dim StartPres As Presentation
Dim macrodocument As String
Dim StartFileName As String
Set StartPres = ActivePresentationStartFileName = "slides 07-25-23.pptx" ' Assign the filename directly
Presentations("000-macros for report.pptm").Windows(1).Activatemacrodocument = StartPres.Slides(1).Shapes _
("Macro Doc Value").TextFrame.TextRange.Text
Presentations(StartFileName).Windows(1).Activate

In this code, the StartFileName variable is assigned the filename directly as a string. You can replace "slides 07-25-23.pptx" with the actual filename if it varies each time.

Note that the line macrodocument = StartPres.Slides(1).Shapes("Macro Doc Value").TextFrame.TextRange.Text assumes that the "Macro Doc Value" shape is located on the first slide of the "slides 07-25-23.pptx" presentation. If the shape is on a different slide, you'll need to adjust the slide index accordingly.

Guanli
10-15-2023, 08:34 PM
The provided code snippet assumes that the filename is constant and hardcoded as "slides 07-25-23.pptx". If the filename varies each time or needs to be dynamic, you can replace it with a variable that holds the actual filename. Here's an example of how you can modify the code to use a variable for the filename:

Dim StartFileName As String
StartFileName = "your_actual_filename.pptx"
' Rest of the code...
Set StartPres = StartApp.Presentations.Open(StartFileName)
' Rest of the code... geometry dash scratch (https://geometrydash-scratch.com)