Consulting

Results 1 to 6 of 6

Thread: Error 438 in access

  1. #1
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    4
    Location

    Error 438 in access

    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

  2. #2
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    that is the wrong command. use: xlbook.visible = true

  3. #3
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    4
    Location
    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.

  4. #4
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    yes you must open the workbook

    xl.workbooks.open MySheetPath

  5. #5
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    4
    Location
    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.

  6. #6
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    4
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •