Removing Reference To Excel
Dear Reader,
I am writing a program with the help of a very talented guy and he helped me write a code to save colors to an Excel Spreadsheet.
Allow me to get more detailed, on the main Form there is a VSFlexGred that opens up an Excel Workbook when the User clicks the Open button on the top left side of the Form. Upon clicking Open, the User opens up a Directory Path and chooses the XLS Workbook to open. When it is Opened it displays the first Spreadsheet of the Workbook, which is the one I want. It populates the VSFlexGrid so the User can view the data in VB.
So here's the thing I'm trying to do. Below that VSFlexGrid the guy, mentioned before, set up a color selector where upon choosing a color the User could highlight a row, hit the Apply Color Command Button, and the row of the VSFlexGrid that was highlighted would be turned the respective color. Now saving these colors so they would be used was the problem. I'm using this code here in my Form that is giving me some trouble and I'm recieving an error code.
Code:
Private Sub RemoveReferenceToExcel()
Set objSH = Nothing
If Not objWB Is Nothing Then objWB.Close True
Set objWB = Nothing
If Not objExcel Is Nothing Then objExcel.Application.Quit
Set objExcel = Nothing
End Sub
The error message is this
Quote:
Microsoft Visual Basic
Run-time error '424':
Object Required
Continue -- End -- Debug -- Help
Continue is shadowed out, End ends the program which I don't want to do yet, and Help is pointless. Debug points me to this line.
Code:
If Not objWB Is Nothing Then objWB.Close True
That's where the error message comes from.
Also, I'm silly for not mentioning this before the error messages BUT this message OCCURS when I try and close the program. Which is essential to saving the color of the row. If anyone needs any additional information I'll see what I can provide. If anyone has insight to why this is happening please let me know.
Thank you for taking the time to read this message.
Re: Removing Reference To Excel
My guess is that there is no object called "objWB" on the form or within the current project. I notice in the first part of the code you posted you have:
vb Code:
If Not objWB Is Nothing Then objWB.Close True
Set objWB = Nothing
Why not write it like:
vb Code:
objWB.Close True
Set objWB = Nothing
Re: Removing Reference To Excel
Thank you for your suggestion. I will take a look at the code when I go into the office today at 12PM PST. Thanks again.