PDA

View Full Version : [SOLVED:] Error 438 in access



dstille
01-12-2018, 11:42 AM
I am getting the error 438 on the following line of code. All my company did was switch to a new server computer which runs EXCEL 2016 and ACCESS 2016. I do not understand why this code no longer works.

Thank you in advance.

Dim MySheetPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet

'Tell it location of actual Excel file
MySheetPath = "C:\Users\Public\Documents\WORK ORDERS\Job Number Work Order.xlsx"

'Open Excel and the workbook
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)

'Make sure excel is visible on the screen
Xl.Visible = True
XlBook.Window.Visible = True -------- Error happens here

ranman256
01-15-2018, 07:47 AM
that is the wrong command. use: xlbook.visible = true

dstille
01-15-2018, 08:11 AM
That didn't change the error either. I commented that line out and ran the code. Further down the code I do a save of the excel book with certain fields inserted. The code saves a blank grey workbook. So I think that the error is being caused because for some reason it doesn't open my excel worksheet.

ranman256
01-15-2018, 08:18 AM
yes you must open the workbook

xl.workbooks.open MySheetPath

dstille
01-16-2018, 07:49 AM
That line gives me an error of variable not defined and highlights the X1. Would this be a problem switching to version 2016 or even Windows 10 Pro? The code opens excel but the workbook is gray with no cells.

dstille
01-16-2018, 11:45 AM
I finally resolved this issue. For whatever reason there were two excel windows open, probably since I opened the application and the book. Access wasn't sure which excel book to move my items to so it didn't move any. I had to open the excel application then through excel open the book. Works fine now. Thank you for your input and assistance.