Results 1 to 10 of 10

Thread: Excel 2010 won't start maximized

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    586

    Excel 2010 won't start maximized

    I've got a VB6 program that opens Excel. Everything works fine on most computers but on one computer Excel starts minimized. This is Excel 2010 and the .displayfullscreen method doesn't seem to be supported.

    Anybody have any idea how to get Excel 2010 to come up maximized?

    Code:
       Dim exExcel As Object
       Dim oBook As Object
       Dim oSheet As Object
       Set exExcel = CreateObject("Excel.Application")
       exExcel.Workbooks.Open (FileToFill)         
       Set oSheet = exExcel.Sheets(1)
             
       oSheet.Cells(1, 1).value = "My value goes here"
     
       ' had to comment this line out because it causes an error
       ' exExcel.DisplayFullScreen = True
       
       exExcel.Show
             
       Set oSheet = Nothing
       Set oBook = nothing
       Set exExcel = Nothing

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel 2010 won't start maximized

    try
    exExce.WindowState=xlMaximized
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    586

    Re: Excel 2010 won't start maximized

    Quote Originally Posted by westconn1 View Post
    try
    exExce.WindowState=xlMaximized
    Tried that a long time back...

    Error: 1004 Unable to set the WindowState property of the Application class

    That comes up whether I put the xlMaximized before the show or after it. But thanks for the suggestion.

    Any other ideas?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel 2010 won't start maximized

    it may be that it can not work within the procedure that opens excel
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Excel 2010 won't start maximized

    exExcel.Show

    is not valid syntax try;

    exExcel.Visible = True

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel 2010 won't start maximized

    Try this

    Declare this at the top...

    Const xlMaximized = -4137

    and then try

    exExcel.WindowState=xlMaximized

    Code:
    Const xlMaximized = -4137
    
    Sub Sample()
        Dim exExcel As Object, oBook As Object, oSheet As Object
        Dim FileToFill As String
        
        Set exExcel = CreateObject("Excel.Application")
        Set oBook = exExcel.Workbooks.Open(FileToFill)
        Set oSheet = oBook.Sheets(1)
             
        oSheet.Cells(1, 1).Value = "My value goes here"
     
        exExcel.Visible = False
        exExcel.WindowState = xlMaximized
        
        '~~> Rest of code
    End Sub
    If the above doesn't work... which I doubt then you can try this alternative as well...

    Code:
    Const xlMaximized = -4137
    
    Sub Sample()
        Dim exExcel As Object, oBook As Object, oSheet As Object
        Dim FileToFill As String
        
        Set exExcel = CreateObject("Excel.Application")
        Set oBook = exExcel.Workbooks.Open(FileToFill)
        Set oSheet = oBook.Sheets(1)
             
        oSheet.Cells(1, 1).Value = "My value goes here"
     
        exExcel.Visible = False
        exExcel.Windows(GetFileName(FileToFill)).WindowState = xlMaximized
        
        '~~> Rest of code
    End Sub
    
    Public Function GetFileName(flname As String) As String
        Dim posn As Integer, i As Integer
        Dim fName As String
        
        posn = 0
        For i = 1 To Len(flname)
            If (Mid(flname, i, 1) = "\") Then posn = i
        Next i
        fName = Right(flname, Len(flname) - posn)
        posn = InStr(fName, ".")
            If posn <> 0 Then
                fName = Left(fName, posn - 1)
            End If
        GetFileName = fName
    End Function
    Sid
    Last edited by Siddharth Rout; Jan 15th, 2011 at 08:32 AM. Reason: Added more text
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel 2010 won't start maximized

    oops, missed that xlmaximised might not be a valid constant due to late binding
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    586

    Re: Excel 2010 won't start maximized

    Well thanks very much for the constant value for xlMaximized. Excel is now starting maximized. The problem is that my program is also maximized. Excel is starting but it doesn't have focus. So my program sits on top of Excel and it appears that Excel is minimized to the task bar. It's not. If you minimize my program there's Excel big as life.

    I guess I should have said that I'd like to start Excel both maximized and with focus. Any ideas?

    Thanks.

    Bob

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel 2010 won't start maximized

    hide your form?
    me.hide
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Excel 2010 won't start maximized

    AppActivate perhaps;

    Code:
    Private Sub Command1_Click()
       
       With CreateObject("Excel.Application")
            .workbooks.open "BookOne.xls"
            .cells(1, 1) = "My Value"
            
            .Visible = True
            .displayfullscreen = True
            AppActivate .Caption
        End With
       
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width