I have a PowerPoint Presentation that gets filled with pictures by a VBA script attached to it. I want to automatically open the Presentation and run the macro. Here's what I have tried:
- turning the script into an add-in as shown here: it ran when I clicked activated it, but never when I simply opened powerpoint.
- downloaded a pre-built add in, and called my script sub auto_open(). This worked, but because it is a macro enabled file(?), but I have to open powerpoint up and enable the add in before opening the file, so it's not much more automatic than just running the macro
Running PowerPoint through MatLab. I used the following commands that I found here, which do open powerpoint, and the file I am interested in.
g = actxserver('PowerPoint.Application');
Presentation = invoke(g.Presentations,'Open','\\path\Automatic_NEdN_Template2.pptm')
a = invoke(Presentation.Application,'Run','Auto_Open',[])
With small test cases, it even seemed to work--I could call a vba function that read data from a file and it would return the data to matlab, but when I tried to call the one that makes pictures, it returned NaN and the PowerPoint was not filled.
Ideally, I'd like to double click on something, then have PowerPoint open, and run my script.
Here are some code snippets if they'll help:
Function read_in_data_from_txt_file(strFileName As String) As String()
Dim dataArray() As String
Dim i As Integer
'Const strFileName As String = "C:\H5_Samples\Plots\WeeklyPlots\zz_avgTemp.txt"
Open strFileName For Input As #1
' -------- read from txt file to dataArrayay -------- '
i = 0
Do Until EOF(1)
ReDim Preserve dataArray(i)
Line Input #1, dataArray(i)
i = i + 1
Loop
Close #1
read_in_data_from_txt_file = dataArray
End Function
And here is the code for the pictures:
Function Auto_Open() As String
Dim oSlide As Slide
Dim oPicture As Shape
Dim oText As Variant
Dim heightScaleFactor As Single
Dim widthScaleFactor As Single
Dim width As Single
heightScaleFactor = 2.1
widthScaleFactor = 2.1
width = 205
Height = 360
ActiveWindow.View.GotoSlide 2
Set oSlide = ActiveWindow.Presentation.Slides(2)
Set oPicture = oSlide.Shapes.AddPicture("C:\H5_Samples\Plots\WeeklyPlots\Nominal DS Real spectra.png", _
msoFalse, msoTrue, 1, 150, Height, width)
Set oPicture = oSlide.Shapes.AddPicture("C:\H5_Samples\Plots\WeeklyPlots\Nominal DS Imaginary spectra.png", _
msoFalse, msoTrue, 350, 150, Height, width)
'Full Resolution
ActiveWindow.View.GotoSlide 3
Set oSlide = ActiveWindow.Presentation.Slides(3)
Set oPicture = oSlide.Shapes.AddPicture("C:\H5_Samples\Plots\WeeklyPlots\Full Resolution DS Real spectra.png", _
msoFalse, msoTrue, 1, 150, Height, width)
Set oPicture = oSlide.Shapes.AddPicture("C:\H5_Samples\Plots\WeeklyPlots\Full Resolution DS Imaginary spectra.png", _
msoFalse, msoTrue, 350, 150, Height, width)
End Function