Solved Error 1004 Unable to set the WindowState property of the Application class (1 Viewer)

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
I want to do late binding on an Excel application object but I am having an Error 1004 (Unable to set the WindowState property of the Application class) if I do it that way. The code runs fine when the Excel object library is referenced.

Code:
Dim objExcel        As Object
Dim objWorkbook     As Object
Dim objWorksheet    As Object

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("W:\System\File (Template).xltx")
    
objExcel.Application.Visible = True
objExcel.Application.WindowState = xlMinimized 'Error 1004 here

Thanks for the help!
 

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
As additional info, I am using Access 365 but computers in our office also use 2013 and 2016 versions.
 

Minty

AWF VIP
Local time
Today, 15:26
Joined
Jul 26, 2013
Messages
10,354
Access doesn't understand the value of xlMinimized

in excel or access if you have the Excel references set type this into the immediate window;
? xlMinimized
And you should get
-4140
Which is the value of the constant in Excel.
 
Last edited:

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
Hi Minty,

You're right. I looked at the Excel constants in the declaration and xlMinimized is not included. Would you know its value?

Code:
Public Const xlAutomatic = -4105
Public Const xlDiagonalDown = 5
Public Const xlDiagonalUp = 6
Public Const xlEdgeBottom = 9
Public Const xlEdgeLeft = 7
Public Const xlEdgeRight = 10
Public Const xlEdgeTop = 8
Public Const xlInsideHorizontal = 12
Public Const xlInsideVertical = 11
Public Const xlNone = -4142
Public Const xlContinuous = 1
Public Const xlDouble = -4119
Public Const xlExpression = 2
Public Const xlSolid = 1
Public Const xlThick = 4
Public Const xlThin = 2
Public Const xlUp = -4162
Public Const xlThemeColorDark1 = 1
Public Const xlThemeColorDark2 = 3
Public Const xlSortOnValues = 0
Public Const xlAscending = 1
Public Const xlSortNormal = 0
Public Const xlYes = 1
Public Const xlTopToBottom = 1
Public Const xlPinYin = 1
Public Const xlThemeFontMinor = 2
Public Const xlLandscape = 2
Public Const xlPortrait = 1
Public Const xlValues = -4163
Public Const xlPart = 2
Public Const xlByRows = 1
Public Const xlByColumns = 2
Public Const xlNext = 1
Public Const xlPrevious = 2
Public Const xlPie = 5
Public Const xlUnderlineStyleSingle = 2
Public Const xlUnderlineStyleNone = -4142
Public Const xlCenter = -4108
Public Const xlBottom = -4107
Public Const xlTop = -4160
Public Const xlContext = -5002
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:26
Joined
May 7, 2009
Messages
19,169
I get xlMinimized as -4137
 

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
Got it now. Used debug.print to show me the value. Thanks for pointing me to the right direction.

Public Const xlMinimized = -4140
 

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
Sorry arnelgp, I posted my last comment while not having read your comment. I wonder why we get different values?
 

Minty

AWF VIP
Local time
Today, 15:26
Joined
Jul 26, 2013
Messages
10,354
I did put the value in my reply post - weird the Arnelgp is getting a different value.
I'm using the latest Office365 version, wonder if it has changed, seems unlikey.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:26
Joined
May 7, 2009
Messages
19,169
sorry, minty, see, I posted Const for Maximized.
 

jocph

Member
Local time
Today, 23:26
Joined
Sep 12, 2014
Messages
61
Thank you both minty and arnelgp! Much appreciated.
 

Users who are viewing this thread

Top Bottom