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?
stops at the -- Set wBookSvy = wBook.Sheets(1)
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)