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
Re: Excel 2010 won't start maximized
try
exExce.WindowState=xlMaximized
Re: Excel 2010 won't start maximized
Quote:
Originally Posted by
westconn1
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?
Re: Excel 2010 won't start maximized
it may be that it can not work within the procedure that opens excel
Re: Excel 2010 won't start maximized
exExcel.Show
is not valid syntax try;
exExcel.Visible = True
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
Re: Excel 2010 won't start maximized
oops, missed that xlmaximised might not be a valid constant due to late binding
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
Re: Excel 2010 won't start maximized
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