0

I have this macro in an automatically created data file (part of the creation is inserting and running the macro). I want to open a template file and then need to run a PPT macro that takes in the excel data file name. The one that called the macro (data1.xlsm) I have this but can't figure out the macro call with the file name.

Dim PPTObj As Object 
Set PPTObj =    CreateObject("PowerPoint.application") 
With PPTObj 
.Presentations.Open Filename:="C:\Presentations\Company\Template.pptm" 
.Run  "Template.pptm!MainMacro" 
End With

.Run "Template.xlsm!MainMacro(filename)" is what I am looking for.

Maybe the other direction is to get the object in PPT. But how do I get the data file name/path without knowing it beforehand?

Set wb - getobject(openwexcelfile)

Since another program (not office) is creating the data file, I do not know it's name or directory, but it is the file calling the powerpoint macro and it will be open.

Thanks for any insight.

mooseman
  • 1,997
  • 2
  • 17
  • 29
  • 1
    Just pass a parameter. The [MSDN documentation](https://msdn.microsoft.com/en-us/library/office/ff744221.aspx) on Application.Run shows pretty much exactly what you're looking for. – Comintern Sep 26 '16 at 16:48
  • Thanks, that worked, I couldn't find out how to pass that parameter. I was trying to do it inside the quotes. .Run "Template.pptm!MainMacro" ,filename,filepath – mooseman Sep 26 '16 at 17:31

1 Answers1

0

Thanks Comintern for the insight. Here is the final solution. The sleep is to allow PPT App to open before trying to run the macro.

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub auto_open()

fname = ActiveWorkbook.Name
Path = ActiveWorkbook.Path

Dim PPTObj As Object
Set PPTObj = CreateObject("PowerPoint.application")
PPTObj.Presentations.Open Filename:="C:\presentation\Template.pptm"
    Sleep (3000)
PPTObj.Run "Template.pptm!Main", fname, Path
End Sub
mooseman
  • 1,997
  • 2
  • 17
  • 29