Removing Reference To Excel-VBForums
Results 1 to 3 of 3

Thread: Removing Reference To Excel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2012
    Posts
    209

    Question 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
    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.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    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:
    1. If Not objWB Is Nothing Then objWB.Close True
    2.     Set objWB = Nothing

    Why not write it like:

    vb Code:
    1. objWB.Close True
    2.     Set objWB = Nothing
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2012
    Posts
    209

    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.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.