Results 1 to 9 of 9

Object Variable or With block variable not set - Error 91

Threaded View

  1. #1
    Registered User
    Join Date
    05-02-2016
    Location
    Kenosha, Wisconsin
    MS-Off Ver
    MS 2010
    Posts
    4

    Object Variable or With block variable not set - Error 91

    Good day,

    I'm not the fondest when it comes to knowledge with Excel, so slightly asking a newbie question and looking for a possible resolution.

    The current output I have is as follows:


    Public Sub SetNewInvoiceNo()
    '*************************************************************************
    'A new invoice number will be generated everytime the document is opened.
    '*************************************************************************
    strInvNo = Trim(Right(Str$(DatePart("yyyy", Date)), 2)) & _
               Trim(Str$(DatePart("y", Date))) & _
               Trim(Str$(DatePart("h", Time))) & _
               Trim(Str$(DatePart("n", Time))) & _
               Trim(Str$(DatePart("s", Time)))
    strInvNo = strInvNo
    strNewInvoice = Str(Val(strInvNo))
    ActiveSheet.Protect
    ActiveWorkbook.Worksheets(1).Cells(6, 16).Value = strInvNo                     <-------string that's causing the error
    ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True
    ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True
    MsgBox "A new invoice# is generated each time this document is opened. " & _
           "This feature lets you use your original invoice as a model for creating a new invoice. " & _
           vbCrLf & "     Previous Invoice Number: " & strOldInvoice & _
           vbCrLf & "     New Invoice Number:      " & strNewInvoice, vbOKOnly, "New Invoice Number Generated"
    
    
    End Sub
    I've gotten this to work before without receiving this error, unsure of what I changed to get it to work to be honest. I've researched this throughout many points of google but stumped as to what is stopping this from working correctly.

    Any insight would be greatly appreciated and to help a newbie understand this.


    Thanks!!


    Shawn




    *Edit* When I close and reload the document, I receive a new error of 1004 - Out of Stack Space. This has got me confused even more now >,<
    Last edited by alansidman; 05-02-2016 at 07:21 PM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  2. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  3. [SOLVED] Excel VBA error code 91: Object variable or with block variable not set
    By wilnexpc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 11:46 AM
  4. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  5. Object variable or With block variable not set Error during sorting program
    By BlahBlahBlahBlahBlah in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2012, 07:57 AM
  6. Error 91 object variable block variable not set when importing a CVS file
    By ReportBuilder2011 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2011, 11:48 AM
  7. Object variable or With block variable not set" error message
    By JoeS in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-22-2009, 11:51 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1