PDA

View Full Version : Help loading a user form



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

neverfall
04-07-2010, 07:23 AM
I've got all the code for this addon finished and functional now (for the most part). I still haven't been able to get powerpoint to load the user form. There seems to be very little information online regarding userforms in addons, and Microsoft Help only has snippits of information on how powerpoint works with userforms.


The UserForms collection is a collection whose elements represent each loaded UserForm in an application. The UserForms collection has a Count property, an Item property, and an Add method. Count specifies the number of elements in the collection; Item (the default member) specifies a specific collection member; and Add places a new UserForm element in the collection...
...Similarly, you can pass an argument to a procedure as type UserForm. You can create multiple instances of user forms in code by using the New keyword in Dim, Set, and Static statements. from powerpoint's vba help doc

I've tried things like "Dim tearoutDialogForm As New tearoutDialog" in my autoload, but I think the issue is that it's never loading "tearoutDialog" in the first place. I've tried many variations of "Set tearoutDialogForm = UserForms.Add()" as well, and can't seem to find a way to make powerpoint recognize it. It's possible that there is another issue here, but my code still works fine as an addon as long as there's no userform involved. Perhaps saving out the form and then importing it as an external file might have better results? I haven't found out how to do that either.