Error 1004 with macro to Insert>object>Create from file>Browse

Hello Experts.

I am currently experiencing difficulties with my macro to insert embedded files, such as PDF's.

I found the macro in another forum, and it acutally Works perfectly. I've assigned it to a button, and whenever i hit the button, the browse window turns up. There is just one exception. If i cancel the browse window, instead of actually inserting the file, i get the error 1004 mentioned in subject.

This is how my macro looks like.

Sub Macro1()
'declare a variable to hold the file name:'
Dim FName As String

'load the variable via an input box:'
FName$ = Application.GetOpenFilename

'get the file:
ActiveSheet.OLEObjects.Add(Filename:=FName, _
Link:=False, _
DisplayAsIcon:=False).Select

End Sub

Does anyone know whats wrong?

Thanks

Regards - Emil

Add IF

You should add an "If" section to handle the case when no file was chosen to open:

If FName$ <> False
' here you have your code "ActiveSheet.OLEObjects.Add..."
End If