danitouffaha
08-22-2014, 07:40 AM
Hi,
I have a vbs script that is scheduled to run daily, opens an excel workbook, unprotects it, does some tasks then exits after protecting it again.
The process worked for a good time flawlessly.
Recently, I started getting an error when exiting.
Code:
when the script opens the workbook, there is no problem
Private Sub Workbook_Open()
Call logStartFunctionSub(True, True, "Workbook_Open", Me.Name)
Set selRange = Selection ' this line works perfectly
activeRow = ActiveCell.Row
activeColumnNb = ActiveCell.Column
activeSheetName = ActiveSheet.Name
............
end Sub
but when exiting :
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call logStartFunctionSub(True, True, "Workbook_BeforeClose", Me.Name)
Dim activeSheetName As String
'On Error Resume Next
Set selRange = Selection ' here if I hover Selection I see "Selection = <Type mismatch>" and this is throwing an error. Adding the On Error is not an option, because this line is used all over the code, and this will leave the workbook unprotected. PLEASE HELP as this is driving me crazy
activeRow = ActiveCell.Row
activeColumnNb = ActiveCell.Column
activeSheetName = ActiveSheet.Name
......
End Sub
I tried to add an explicit range set before the problematic line and it is always erroring out.
Any ideas?
Thanks a lot
Dani
I have a vbs script that is scheduled to run daily, opens an excel workbook, unprotects it, does some tasks then exits after protecting it again.
The process worked for a good time flawlessly.
Recently, I started getting an error when exiting.
Code:
when the script opens the workbook, there is no problem
Private Sub Workbook_Open()
Call logStartFunctionSub(True, True, "Workbook_Open", Me.Name)
Set selRange = Selection ' this line works perfectly
activeRow = ActiveCell.Row
activeColumnNb = ActiveCell.Column
activeSheetName = ActiveSheet.Name
............
end Sub
but when exiting :
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call logStartFunctionSub(True, True, "Workbook_BeforeClose", Me.Name)
Dim activeSheetName As String
'On Error Resume Next
Set selRange = Selection ' here if I hover Selection I see "Selection = <Type mismatch>" and this is throwing an error. Adding the On Error is not an option, because this line is used all over the code, and this will leave the workbook unprotected. PLEASE HELP as this is driving me crazy
activeRow = ActiveCell.Row
activeColumnNb = ActiveCell.Column
activeSheetName = ActiveSheet.Name
......
End Sub
I tried to add an explicit range set before the problematic line and it is always erroring out.
Any ideas?
Thanks a lot
Dani