Rick_Stanich
New member
- Joined
- Sep 19, 2025
- Messages
- 2
- Programming Experience
- 1-3
I have a userform with a Button, I am trying to open an existing excel file for editing. I keep getting this error (See image).
Any help is appreciated.
Form1.vb
Code:
Any help is appreciated.
Form1.vb
VB.NET:
Imports System.IO
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Exce
Code:
VB.NET:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'MsgBox("Load Data") 'for testing
MsgBox(TextBox1.Text) 'for testing
'"V:\CMM Data Files\Excel Files\Shoe GDT\#MSA-Masters\#Master-Shoe-MSA 32.xlsx")
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("V:\CMM Data Files\Excel Files\Shoe GDT\#MSA-Masters\#Master-Shoe-MSA 32.xlsx")
xlWorkSheet = xlWorkBook.Sheets("MSA")
xlApp.Visible = True
'display the cells value B2
MsgBox(xlWorkSheet.Cells(1, 15).value)
'edit the cell with new value
'removed
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub