[英]Compile Error when I try to activate presentation
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.