The code works fine for me, which is exactly what I'd expect.
So you need to do a couple of things:
1) Check when you are executing that code: if it's from a constructor, the forms you want may not be fully initialized yet for example.
2) Check your UIPermission:
Quote:
Caller must have permission to access all windows, as defined by the AllWindows value of the UIPermissionWindow enumeration.
(
Application.OpenForms Property (System.Windows.Forms) | Microsoft Docs[
^])