Application will minimize, but will not maximize when called

Application will minimize, but will not maximize when called

I was able to work on a Sub to minimize my application. However, when I try to maximize, it won't do it.  Here is my code to minimize:

Module sheetView

    Public WB As Excel.Workbook = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)

   Sub minimizeWindow()

        With WB

            .Application.WindowState = XlWindowState.xlMinimized


        End With

    End Sub

This works perfectly, but when I want to maximize, it wont. For example, on my maximize code, is suppose to maximize excel and select a particular sheet. The sheet is selected but the application is not maximized.

    Sub maximizeWindow()


        With WB

            .Application.WindowState = XlWindowState.xlMaximized
            .Sheets("employeeBoard").Select()

        End With

    End Sub

End Module

Public Class Form1
 
    'Declare functions and constants
    Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
    Private Const SW_SHOWMAXIMIZED As Integer = 3
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        'Specify part of the window title you want. Get its window handle:
        Dim hwnd As String = findPartialTitle("Notepad")
 
        'Send hwnd to showwindow function
        ShowWindow(hwnd, SW_SHOWMAXIMIZED)
 
    End Sub
 
    'FUNCTION: Find handle by partial window title
    Private Function findPartialTitle(ByVal partialTitle As String) As IntPtr
        For Each p As Process In Process.GetProcesses()
            If p.MainWindowTitle.IndexOf(partialTitle, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
                Return p.MainWindowHandle
            End If
        Next
        Return IntPtr.Zero
    End Function
 
End Class

  • Back aarticle:No
  • Next aarticle: No
  • Copyright © 2007-2012 www.chuibin.com Chuibin Copyright