Error 424 when opening .xlsx from Access 2010 (1 Viewer)

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
Hi, when opening an excel spreadsheet from a link on a form the spreadsheet opens in a minimised state. Adding this line of code fixes the problem and opens the spreadsheet with focus.

Code:
Set xlApp.UserControl = True
However, when I close the spreadsheet there's an error message behind it - 424 - Object Expected. Here's the full code:

Code:
Private Sub txtWorksPriceLink_Click()
 Dim xlApp As Object
Dim xlBook As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("Z:\" & Me.txtProjID & "\WorksPrice.xlsx")
xlApp.Visible = True
Set xlApp.UserControl = True
Set xlApp = Nothing
 End Sub
Any help much appreciated

Thanks
 

vbaInet

AWF VIP
Local time
Today, 08:09
Joined
Jan 22, 2010
Messages
26,374
Closing the Excel workbook manually or through code?
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
Actually my OP isn't quite right. The spreadsheet opens as expected with the error message behind it - it's nothing to do with closing the form.
 

vbaInet

AWF VIP
Local time
Today, 08:09
Joined
Jan 22, 2010
Messages
26,374
What is the full error message and which line does it highlight?
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
The full error is 'Runtime error 424, Object required'

This is the highlighted code:

Code:
Set xlApp.UserControl = True

Thanks
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
I've already tried it without Set, without Set the spreadsheet opens minimised.
 

vbaInet

AWF VIP
Local time
Today, 08:09
Joined
Jan 22, 2010
Messages
26,374
I've already tried it without Set, without Set the spreadsheet opens minimised.
The UserControl property is not an object and therefore it will fail if you use Set. winshent has given you a link that would enable you maximize the spreadsheet.
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
Thanks for your help guys but still no joy, when I try
Code:
[FONT=Courier New]xlApp.WindowState = xlMaximized[/FONT]
Excel opens but with the following error:
Runtime error 1004 - Unable to windowstate property of the Application class.

When I say I want excel to open 'maximised' what I actually mean is I want it to open visible and not minimised in the toolbar.

This code should make it visible but it's not working

Code:
xlApp.Visible = True
 

winshent

Registered User.
Local time
Today, 08:09
Joined
Mar 3, 2008
Messages
162
Have you tested with a blank workbook instead of WorksPrice.xlsx?
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
Apologies, full error should read:

Unable to Set the Windowstate property of the Application Class
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
This is the code

Code:
Private Sub txtWorksPriceLink_Click()
 Dim xlApp As Object
Dim xlBook As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("Z:\" & Me.txtProjID & "\WorksPrice.xlsx")
xlApp.Visible = True
Set xlApp.UserControl = True
Set xlApp = Nothing
 End Sub
 

wilsation

Registered User.
Local time
Today, 08:09
Joined
Jul 28, 2014
Messages
44
Here's the code

Code:
Private Sub txtWorksPriceLink_Click()
 Dim xlApp As Object
Dim xlBook As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("Z:\" & Me.txtProjID & "\WorksPrice.xlsx")
xlApp.Visible = True
 xlApp.Windowstate = xlMaximized
Set xlApp = Nothing
 End Sub
 

vbaInet

AWF VIP
Local time
Today, 08:09
Joined
Jan 22, 2010
Messages
26,374
You've just added that line. Can you re-run the code and paste exactly the code that fails.
 

Users who are viewing this thread

Top Bottom