G
Geoff Cox
Hello,
I have added a macro but the Run command in Tools/Macro/Macros is
greyed out. If I try running the macro from the VBA Editor I get the
error message "The macros in this project are disabled etc" .. and the
mentions the host application?!
I have tried various options from MS but cannot get the Run command
back.
If I add the macro to another ppt this will work so why not in the
other ones?
Also, how do I run a macro which works on all files in a folder? Must
I do this from within one of the ppt files? Cann't I run VBA Editor
separately from the ppt file?
Lastly the following code adds an action button to the first slide in
each presentation (except the ppt file from which I am running the
macro!) but I want to add the action button to the last file of each
ppt file .... how do I do this?
Cheers
Geoff
PS you can see that I am trying to combine code from Steve's web site
with a macro recording ...
Sub ForEachPresentation()
' Run a macro of your choosing on each presentation in a folder
Dim rayFileList() As String
Dim FolderPath As String
Dim FileSpec
Dim strTemp As String
Dim x As Long
' EDIT THESE to suit your situation
FolderPath = "c:\fred\activities\" ' Note: MUST end in \
FileSpec = "*.ppt"
' END OF EDITS
' Fill the array with files that meet the spec above
ReDim rayFileList(1 To 1) As String
strTemp = Dir$(FolderPath & FileSpec)
While strTemp <> ""
rayFileList(UBound(rayFileList)) = FolderPath & strTemp
ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
String
strTemp = Dir
Wend
' array has one blank element at end - don't process it
' don't do anything if there's less than one element
If UBound(rayFileList) > 1 Then
For x = 1 To UBound(rayFileList) - 1
Call MyMacro(rayFileList(x))
Next x
End If
End Sub
Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in
ForEachPresentation
' strMyFile is set to the file name each time
' Probably at a minimum, you'd want to:
Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)
With oPresentation
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeActionButtonForwardorNext,
189.88, 389.12, 153.12, 39.62).Select
With
ActiveWindow.Selection.ShapeRange.ActionSettings(ppMouseClick)
.Hyperlink.Address = "C:\a-temp1\fred\menu.ppt"
.SoundEffect.Type = ppSoundNone
.AnimateAction = msoTrue
End With
With ActiveWindow.Selection.ShapeRange.ActionSettings(ppMouseOver)
.Action = ppActionNone
.SoundEffect.Type = ppSoundNone
.AnimateAction = msoFalse
End With
oPresentation.Save
oPresentation.Close
End With
End Sub
I have added a macro but the Run command in Tools/Macro/Macros is
greyed out. If I try running the macro from the VBA Editor I get the
error message "The macros in this project are disabled etc" .. and the
mentions the host application?!
I have tried various options from MS but cannot get the Run command
back.
If I add the macro to another ppt this will work so why not in the
other ones?
Also, how do I run a macro which works on all files in a folder? Must
I do this from within one of the ppt files? Cann't I run VBA Editor
separately from the ppt file?
Lastly the following code adds an action button to the first slide in
each presentation (except the ppt file from which I am running the
macro!) but I want to add the action button to the last file of each
ppt file .... how do I do this?
Cheers
Geoff
PS you can see that I am trying to combine code from Steve's web site
with a macro recording ...
Sub ForEachPresentation()
' Run a macro of your choosing on each presentation in a folder
Dim rayFileList() As String
Dim FolderPath As String
Dim FileSpec
Dim strTemp As String
Dim x As Long
' EDIT THESE to suit your situation
FolderPath = "c:\fred\activities\" ' Note: MUST end in \
FileSpec = "*.ppt"
' END OF EDITS
' Fill the array with files that meet the spec above
ReDim rayFileList(1 To 1) As String
strTemp = Dir$(FolderPath & FileSpec)
While strTemp <> ""
rayFileList(UBound(rayFileList)) = FolderPath & strTemp
ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
String
strTemp = Dir
Wend
' array has one blank element at end - don't process it
' don't do anything if there's less than one element
If UBound(rayFileList) > 1 Then
For x = 1 To UBound(rayFileList) - 1
Call MyMacro(rayFileList(x))
Next x
End If
End Sub
Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in
ForEachPresentation
' strMyFile is set to the file name each time
' Probably at a minimum, you'd want to:
Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)
With oPresentation
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeActionButtonForwardorNext,
189.88, 389.12, 153.12, 39.62).Select
With
ActiveWindow.Selection.ShapeRange.ActionSettings(ppMouseClick)
.Hyperlink.Address = "C:\a-temp1\fred\menu.ppt"
.SoundEffect.Type = ppSoundNone
.AnimateAction = msoTrue
End With
With ActiveWindow.Selection.ShapeRange.ActionSettings(ppMouseOver)
.Action = ppActionNone
.SoundEffect.Type = ppSoundNone
.AnimateAction = msoFalse
End With
oPresentation.Save
oPresentation.Close
End With
End Sub