Results 1 to 4 of 4

Object variable or with block variable not set

Threaded View

  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:

    Option Explicit
    
    Dim wb1 As Workbook
    Dim wb2 As Workbook
    Dim wb3 As Workbook
    Dim wb4 As Workbook
    
    Sub ActivateAustria()
        Workbooks.Open Filename:="C:\Users\red\Desktop\1st\excel1.xls"
        Windows("excel1.xls").Activate
        wb1 = "excel1.xls"
        Workbooks.Open Filename:="C:\Users\ref\Desktop\1st\excel2.xls"
        Windows("excel2.xls").Activate
        wb2 = "excel2.xls"
        Workbooks.Open Filename:="C:\Users\ref\Desktop\1st\excel3.xls"
        Windows("excel3.xls").Activate
        wb3 = "excel3.xls"
        Workbooks.Open Filename:="C:\Users\ref\Desktop\1st\excel4.xls"
        Windows("excel4.xls").Activate
        wb4 = "excel4.xls"
        ActiveWindow.Close
        ActiveWindow.Close
        ActiveWindow.Close
        ActiveWindow.Close
        MsgBox ("ok")
    End Sub
    
    Sub ActivateHDB()
    
        Workbooks(w1).Worksheets("En_mob").Range("G:G").Activate
    
    End Sub
    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.

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