Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel


        Select Case ComboBox1.SelectedItem

            Case "Open Excel"

                Dim oExcel As New Microsoft.Office.Interop.Excel.Application()
                Dim oBook As Excel.WorkbookClass
                Dim oBooks As Excel.WorkbookClass

                'Start Excel and open the workbook
                oExcel.Visible = True
                'oBooks = oExcel.Workbooks

                oExcel = oExcel.Open("H:\Copy of Book1.xlsm")

                'Run the subroutine.
                oExcel.Run("Sheet1")


Hello, I have an error of MissingMemberException was unhandled after I run the code at
VB
oExcel = oExcel.Open("H:\Copy of Book1.xlsm")


How do I solve this problem? Thank you!!

What I have tried:

I have tried adding references such as Microsoft Office Excel
Posted
Updated 4-Mar-18 23:34pm
Comments
CHill60 5-Mar-18 3:12am    
Are you using the right versions of the references for the excel you are trying to use?

1 solution

You can't open workbook the way you're trying to do that. You have to do this through the collection of workbooks:
VB
oBook = oExcel.Workbooks.Open("H:\Copy of Book1.xlsm")


For further details, please see:
How to: Programmatically Open Workbooks[^]
Excel Object Model Overview[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900