I'm stumped and I feel like I've got to be missing something dumb...
This macro is intended to call and run a macro whose code is contained in another file and "apply" the macro to the open presentation (from which the initial macro was run). I'm getting a Compile error: Method or data member not found on the second to last line. When I comment that line out, the code runs properly but applies the macro to the wrong presentation.
Any ideas?
Thanks in advance, Joe
Function IsPresentationOpen(Name As String) As Boolean
Dim codePres As Presentation
On Error Resume Next
Set codePres = Application.Presentations.Item(Name)
IsWorkBookOpen = (Not codePres Is Nothing)
End Function
Sub Run_Macro()
Dim BriefingTemplate As Presentation
Set BriefingTemplate = Application.ActivePresentation
'Open Joe's Code Workbook
Dim xRet As Boolean
xRet = IsPresentationOpen("CODE.potm")
If xRet Then
Else
Presentations.Open "Direcory\CODE.potm"
End If
'Run Macro
BriefingTemplate.Activate '<<This is the line w/ the error
Application.Run ("'CODE.potm'!Macro"), BriefingTemplate
End Sub
Sub a_RunAll_PM(BriefingTemplate As Presentation)
BriefingTemplate.Activate
Call a_Scorecards_PM
Call CurrentTemps_PM
Call RadarSat_PM
Call Severe_PM
Call Day1_PM
Call Day2
Call JetStream_PM
Call Operational_Impact_PM
Call D1_Headlines_PM
Call D2_Headlines
End Sub
Sub a_Scorecards_PM()
Dim oPic As Shape
Set oPic = ActivePresentation.Slides(1).Shapes.AddPicture( _
FileName:="H:\Weather Briefs\Daily Ops Scorecards\SWA_Page_1.jpg", _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
Width:=720, Height:=540)
ActivePresentation.Slides(1).Copy
ActivePresentation.Slides.Paste 24
End Sub
Rather than "activating" the presentation you want to update, pass the presentation as a parameter to each procedure that needs to access it:
'I am assuming "a_RunAll_PM" is what is called "Macro" in your original question code
Sub a_RunAll_PM(BriefingTemplate As Presentation)
'Removed "Call" as that is obsolete
a_Scorecards_PM BriefingTemplate '<-- pass the presentation as a parameter
CurrentTemps_PM BriefingTemplate '<-- may need to pass to other procedures too?
RadarSat_PM
Severe_PM
Day1_PM
Day2
JetStream_PM
Operational_Impact_PM
D1_Headlines_PM
D2_Headlines
End Sub
Sub a_Scorecards_PM(pres as Presentation)
Dim oPic As Shape
'Use the "pres" parameter rather than "ActivePresentation"
Set oPic = pres.Slides(1).Shapes.AddPicture( _
FileName:="H:\Weather Briefs\Daily Ops Scorecards\SWA_Page_1.jpg", _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
Width:=720, Height:=540)
pres.Slides(1).Copy
pres.Slides.Paste 24
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.