neverfall
04-06-2010, 11:36 AM
I've been working on this addin for powerpoint for a while now, with no previous experience in VBA. It's working great when I'm testing and executing the code from the VBA editor. When I save it as an addon however, it seems to be unable to find the form I'd created. The error I'm getting says "The macro cannot be found or has been disabled because of your security settings".
My security settings should not be an issue. When I skip the dialog form and include all my code in the single module, everything works fine. I'd like to have the flexibility of using a form for options though, as opposed to just having several different addin buttons for all the different variations.
Here's the code I'm using currently, if anybody has any ideas as to how I might be able to get this form to work correctly, it would be greatly appreciated.
Code for loading my addon:
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
MyToolbar = "Demon Tools"
On Error Resume Next
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then
Exit Sub
End If
On Error GoTo ErrorHandler
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
With oButton
.DescriptionText = "Create Tearout"
.Caption = "Tearout"
.OnAction = "CreateTearoutDialog"
.Style = msoButtonIcon
.FaceId = 741
End With
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
Private Sub CreateTearoutDialog()
tearoutDialog.Show
End Sub
Current code for my form:
Sub CreateTearoutButton_Click()
Dim myDocument As Slide
Dim topTearout As Shape
Dim botTearout As Shape
Dim hMult
Dim wMult
Dim oHeight
Dim oWidth
Dim tOffset
Dim hOffset
Dim selLeft
Dim selTop
Dim sizeFactor
Dim curSlideVar
sizeFactor = 1.15
curSlideVar = ActiveWindow.View.Slide.SlideIndex
Set myDocument = ActivePresentation.Slides(curSlideVar)
Set topTearout = myDocument.Shapes.AddPicture("C:\Demon Addons\images\tearoutTopLight.png", _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=1, Top:=1, Width:=1, Height:=1)
Set botTearout = myDocument.Shapes.AddPicture("C:\Demon Addons\images\tearoutBottomLight.png", _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=1, Top:=1, Width:=1, Height:=1)
Set fillTearout = myDocument.Shapes.AddShape(Type:=msoShapeRectangle, Left:=10, Top:=0, Width:=100, Height:=58)
hMult = ActiveWindow.Selection.ShapeRange.Height + 10
wMult = ActiveWindow.Selection.ShapeRange.Width + 20
selLeft = ((ActiveWindow.Selection.ShapeRange.Width * (sizeFactor) - (ActiveWindow.Selection.ShapeRange.Width)) \ 2) - 10
selTop = ((ActiveWindow.Selection.ShapeRange.Height * (sizeFactor * sizeFactor)) - (ActiveWindow.Selection.ShapeRange.Height))
topTearout.ScaleHeight 1, msoTrue
topTearout.ScaleWidth 1, msoTrue
botTearout.ScaleHeight 1, msoTrue
botTearout.ScaleWidth 1, msoTrue
oHeight = topTearout.Height
oWidth = topTearout.Width
topTearout.LockAspectRatio = msoTrue
botTearout.LockAspectRatio = msoTrue
topTearout.Width = wMult
botTearout.Width = topTearout.Width
fillTearout.Width = topTearout.Width
fillTearout.Height = ActiveWindow.Selection.ShapeRange.Height - 20
fillTearout.Fill.ForeColor.RGB = RGB(242, 242, 239)
fillTearout.Line.Visible = msoFalse
With ActivePresentation.PageSetup
topTearout.Left = ActiveWindow.Selection.ShapeRange.Left - 10
topTearout.Top = ActiveWindow.Selection.ShapeRange.Top - 15
fillTearout.Left = topTearout.Left
fillTearout.Top = topTearout.Top + 25
End With
tOffset = ActiveWindow.Selection.ShapeRange.Top - topTearout.Top
hOffset = botTearout.Height - ActiveWindow.Selection.ShapeRange.Height
With ActivePresentation.PageSetup
botTearout.Left = ActiveWindow.Selection.ShapeRange.Left - 10
botTearout.Top = (ActiveWindow.Selection.ShapeRange.Top) - (hOffset - tOffset)
End With
botTearout.PictureFormat.CropTop = botTearout.Height \ 2
topTearout.PictureFormat.CropBottom = topTearout.Height \ 2
botTearout.ZOrder msoBringToFront
topTearout.ZOrder msoBringToFront
Set myRange = myDocument.Shapes.Range(Array(topTearout.Name, botTearout.Name, fillTearout.Name))
Set myGroup = myRange.Group
ActiveWindow.Selection.ShapeRange.ZOrder msoBringToFront
End Sub
Private Sub UserForm_Click()
End Sub
My security settings should not be an issue. When I skip the dialog form and include all my code in the single module, everything works fine. I'd like to have the flexibility of using a form for options though, as opposed to just having several different addin buttons for all the different variations.
Here's the code I'm using currently, if anybody has any ideas as to how I might be able to get this form to work correctly, it would be greatly appreciated.
Code for loading my addon:
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
MyToolbar = "Demon Tools"
On Error Resume Next
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then
Exit Sub
End If
On Error GoTo ErrorHandler
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
With oButton
.DescriptionText = "Create Tearout"
.Caption = "Tearout"
.OnAction = "CreateTearoutDialog"
.Style = msoButtonIcon
.FaceId = 741
End With
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
Private Sub CreateTearoutDialog()
tearoutDialog.Show
End Sub
Current code for my form:
Sub CreateTearoutButton_Click()
Dim myDocument As Slide
Dim topTearout As Shape
Dim botTearout As Shape
Dim hMult
Dim wMult
Dim oHeight
Dim oWidth
Dim tOffset
Dim hOffset
Dim selLeft
Dim selTop
Dim sizeFactor
Dim curSlideVar
sizeFactor = 1.15
curSlideVar = ActiveWindow.View.Slide.SlideIndex
Set myDocument = ActivePresentation.Slides(curSlideVar)
Set topTearout = myDocument.Shapes.AddPicture("C:\Demon Addons\images\tearoutTopLight.png", _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=1, Top:=1, Width:=1, Height:=1)
Set botTearout = myDocument.Shapes.AddPicture("C:\Demon Addons\images\tearoutBottomLight.png", _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=1, Top:=1, Width:=1, Height:=1)
Set fillTearout = myDocument.Shapes.AddShape(Type:=msoShapeRectangle, Left:=10, Top:=0, Width:=100, Height:=58)
hMult = ActiveWindow.Selection.ShapeRange.Height + 10
wMult = ActiveWindow.Selection.ShapeRange.Width + 20
selLeft = ((ActiveWindow.Selection.ShapeRange.Width * (sizeFactor) - (ActiveWindow.Selection.ShapeRange.Width)) \ 2) - 10
selTop = ((ActiveWindow.Selection.ShapeRange.Height * (sizeFactor * sizeFactor)) - (ActiveWindow.Selection.ShapeRange.Height))
topTearout.ScaleHeight 1, msoTrue
topTearout.ScaleWidth 1, msoTrue
botTearout.ScaleHeight 1, msoTrue
botTearout.ScaleWidth 1, msoTrue
oHeight = topTearout.Height
oWidth = topTearout.Width
topTearout.LockAspectRatio = msoTrue
botTearout.LockAspectRatio = msoTrue
topTearout.Width = wMult
botTearout.Width = topTearout.Width
fillTearout.Width = topTearout.Width
fillTearout.Height = ActiveWindow.Selection.ShapeRange.Height - 20
fillTearout.Fill.ForeColor.RGB = RGB(242, 242, 239)
fillTearout.Line.Visible = msoFalse
With ActivePresentation.PageSetup
topTearout.Left = ActiveWindow.Selection.ShapeRange.Left - 10
topTearout.Top = ActiveWindow.Selection.ShapeRange.Top - 15
fillTearout.Left = topTearout.Left
fillTearout.Top = topTearout.Top + 25
End With
tOffset = ActiveWindow.Selection.ShapeRange.Top - topTearout.Top
hOffset = botTearout.Height - ActiveWindow.Selection.ShapeRange.Height
With ActivePresentation.PageSetup
botTearout.Left = ActiveWindow.Selection.ShapeRange.Left - 10
botTearout.Top = (ActiveWindow.Selection.ShapeRange.Top) - (hOffset - tOffset)
End With
botTearout.PictureFormat.CropTop = botTearout.Height \ 2
topTearout.PictureFormat.CropBottom = topTearout.Height \ 2
botTearout.ZOrder msoBringToFront
topTearout.ZOrder msoBringToFront
Set myRange = myDocument.Shapes.Range(Array(topTearout.Name, botTearout.Name, fillTearout.Name))
Set myGroup = myRange.Group
ActiveWindow.Selection.ShapeRange.ZOrder msoBringToFront
End Sub
Private Sub UserForm_Click()
End Sub