|
-
Jan 13th, 2011, 08:46 PM
#1
Thread Starter
Fanatic Member
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
-
Jan 14th, 2011, 03:57 AM
#2
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
-
Jan 14th, 2011, 02:44 PM
#3
Thread Starter
Fanatic Member
Re: Excel 2010 won't start maximized
 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?
-
Jan 14th, 2011, 10:18 PM
#4
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
-
Jan 15th, 2011, 05:27 AM
#5
Re: Excel 2010 won't start maximized
exExcel.Show
is not valid syntax try;
exExcel.Visible = True
-
Jan 15th, 2011, 08:08 AM
#6
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
-
Jan 15th, 2011, 07:20 PM
#7
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
-
Jan 26th, 2011, 04:30 PM
#8
Thread Starter
Fanatic Member
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
-
Jan 27th, 2011, 04:05 AM
#9
Re: Excel 2010 won't start maximized
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
-
Jan 27th, 2011, 04:43 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|