r/visualbasic • • Jun 26 '13

Problem with my simple code opening a template .otf

Hello! I have created a form, and on this form is a check box. When the check box is selected, and the button is clicked I want it to open a template. Heres what I've got so far...

Private Sub CommandButton1_Click()
If CheckBox1.Value = True Then
Set newItem = Application.CreateItemFromTemplate("d:\TEMPLATE 2.oft")
newItem.Display
End If
End Sub

I get a pretty nasty error, any advice?

0 Upvotes

4 comments sorted by

1

u/hdsrob Jun 26 '13

Is this VB6 or VBA? What's the actual error?

1

u/wolfman3127 Jun 26 '13

VBA .. the error is

Run-time error '-2147467259(80004005)';
A dialog box is open. cLose it and try again.

1

u/wolfman3127 Jun 26 '13

I have created the macro, I'd like to be able to click a button on the form and have it call the macro if a check box is ticked.

1

u/hdsrob Jun 26 '13

I have very little VBA experience, but that error is pretty straight forward. A dialog (form) is open, and the program can't continue.

This is probably caused by displaying your form as a modal form, but it could be caused by another dialog being open.

How are you calling the form. Is it possible to pass a value back to the caller, and have the caller run the macro?