Object Variable or with block variable not set - works on one but not another workbook

bdouglas1011

New Member
Joined
Jul 28, 2014
Messages
38
I have got an error saying variable not set ....The code works just fine on another workbook, but not this workbook..I have tried to adjust certain lines but no luck. why would the exact code work on one but not the other with the same files they open?


VBA Code:
Sub UpdateSurvey_NewGT()
    Dim wBook As Workbook
    Dim path As String
    Dim maxRow As Long
    Dim wBookSvy As Worksheet
    Dim Surveys As Worksheet
    Dim col As Long
    Dim row As Long
    
    'get integers for the cell reference in the "Folder Path Cell" on the template sheet
    col = wColNumber(colRegEx(Range("CK30").Text))
    row = CInt(rowRegEx(Range("CK30").Text))
    
    'Turns off screen updates to avoid flashing screen
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationAutomatic
        
    'saving the survey sheet object to a variable
    Set Surveys = ThisWorkbook.Sheets("Surveys")
    
    'setting the defined path for the survey file
    path = cells(row, col).Text
    If Right(path, 1) <> "\" Then path = path
    
    'setting up the generic name for unformatted surveys, "path\<Well Name> Surveys.csv"
    Dim unformatSvy As String: unformatSvy = path + Range("G6").Text + " Surveys.csv"
    
    'Find the file marked as the survey file then exit loop
    For i = row + 2 To row + 15
        If cells(i, col + 11).Value = "Yes" Then
            path = path + cells(i, col + 2).Text
            Exit For
        End If
    Next i
    
    'Open the generated survey file under the object stored by wBook, set the page object in the open book
    'Set wBook = Application.Workbooks.Open(path)
    'Set wBook = Workbooks.Open(path)
    Set Workbook = Workbooks.Open("C:\Users\Remote\Desktop\GENERATED_LOGS\GENERATED_LOGS\HAWK UNIT B001H_Survey.xls")
    Set wBookSvy = wBook.Sheets(1)

stops at the -- Set wBookSvy = wBook.Sheets(1)
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You have the wrong variable on the previous line.
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,674
Messages
6,126,144
Members
449,294
Latest member
Jitesh_Sharma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top