+ Reply to Thread
Results 1 to 4 of 4

Object variable or with block variable not set

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    23

    Object variable or with block variable not set

    Hello, i made a code to read data from specific sheets of multiple workbooks. The error i get is the "object variable or with block variable not set". I made a some changes in the code but it did not worked. So here is the code:

    Please Login or Register  to view this content.
    I get the error in the 9th line where i state "wb1 =". I changed the variables into public instead of dim and nothing happened. I also changed the subs and made them public subs, nothing happened. I also stated the workbook parameters as <Set wb1 = New Workbook> also nothing happened :|
    Any suggestions?
    Last edited by ref; 02-03-2012 at 08:40 AM.

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Object variable or with block variable not set

    You will need to set the values of the workbook e.g.
    Please Login or Register  to view this content.
    Because you have activated the workbooks all you need to do is use the SET command and they will all be = ActiveWorkbook
    You do not need to Activate the workbook as they will be the active workbook so you can remove all the Windows("excelxx.xx").activate from your code

    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Last edited by smuzoen; 02-03-2012 at 06:38 AM.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Object variable or with block variable not set

    Or you could replace:

    Please Login or Register  to view this content.

    with:

    Please Login or Register  to view this content.

    etc ...


    The problem is that you have defined wb1 as a range and "excel1.xls" is a text string.



    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    02-03-2012
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Object variable or with block variable not set

    Quote Originally Posted by smuzoen View Post
    You will need to set the values of the workbook e.g.
    Please Login or Register  to view this content.
    Because you have activated the workbooks all you need to do is use the SET command and they will all be = ActiveWorkbook
    You do not need to Activate the workbook as they will be the active workbook so you can remove all the Windows("excelxx.xx").activate from your code

    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Thank you it did. Been to Perth for X-mas this year btw. Cheers down under.

    Quote Originally Posted by TMShucks View Post
    Or you could replace:

    Please Login or Register  to view this content.

    with:

    Please Login or Register  to view this content.

    etc ...


    The problem is that you have defined wb1 as a range and "excel1.xls" is a text string.



    Regards, TMS
    I'll try this as well, thx.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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