ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Excel - Run-time Error 50289 €“ Can't perform operation (https://www.excelbanter.com/excel-programming/428752-vba-excel-run-time-error-50289-%E2%80%93-cant-perform-operation.html)

Aldo

VBA Excel - Run-time Error 50289 €“ Can't perform operation
 
Hi guys,
I am trying to use the following block of code to insert a function in a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 €“ Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function


JLGWhiz[_2_]

VBA Excel - Run-time Error 50289 - Can't perform operation
 
If you want to access the VB Project by code, you will need to unprotect it.
The whole purpose of the lock VB code for viewing is to prevent changes.
You cannot remove the password protection with code.


"Aldo" wrote in message
...
Hi guys,
I am trying to use the following block of code to insert a function in a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 - Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function




Aldo

VBA Excel - Run-time Error 50289 - Can't perform operation
 
Hi,
I do not intend to change the password. I am the one who set up the password.
I said that, when running the macro (from Excel) while the VBA editor is
closed and password protected, I get the error...
Thanks.


"JLGWhiz" wrote:

If you want to access the VB Project by code, you will need to unprotect it.
The whole purpose of the lock VB code for viewing is to prevent changes.
You cannot remove the password protection with code.


"Aldo" wrote in message
...
Hi guys,
I am trying to use the following block of code to insert a function in a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 - Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function





Patrick Molloy

VBA Excel - Run-time Error 50289 - Can't perform operation
 
but the error occurs when the VB code is locked for viewing... thats locking
it for editing too, which is what your code is trying to do.

"Aldo" wrote in message
...
Hi,
I do not intend to change the password. I am the one who set up the
password.
I said that, when running the macro (from Excel) while the VBA editor is
closed and password protected, I get the error...
Thanks.


"JLGWhiz" wrote:

If you want to access the VB Project by code, you will need to unprotect
it.
The whole purpose of the lock VB code for viewing is to prevent changes.
You cannot remove the password protection with code.


"Aldo" wrote in message
...
Hi guys,
I am trying to use the following block of code to insert a function in
a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 - Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function





JLGWhiz[_2_]

VBA Excel - Run-time Error 50289 - Can't perform operation
 
Let me try to be more specific. When you lock VB Project for Viewing by
setting a password on the project. The project cannot be accessed by
anyone, in any fashion, without first manually unprotecting the project by
using the password. The existing code will run while it is protected, but
it cannot be edited, added to or diminished while the protection is in
effect. To run the code you are trying to run, you will have to manually
unprotect the VBA project.


"Aldo" wrote in message
...
Hi,
I do not intend to change the password. I am the one who set up the
password.
I said that, when running the macro (from Excel) while the VBA editor is
closed and password protected, I get the error...
Thanks.


"JLGWhiz" wrote:

If you want to access the VB Project by code, you will need to unprotect
it.
The whole purpose of the lock VB code for viewing is to prevent changes.
You cannot remove the password protection with code.


"Aldo" wrote in message
...
Hi guys,
I am trying to use the following block of code to insert a function in
a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 - Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function







Patrick Molloy

VBA Excel - Run-time Error 50289 €“ Can't perform operation
 
are you doing this correctly? its very rare that one would need code to
write more code. And if you're inserting a function into a worksheet, its
not clear from your code either.

"Aldo" wrote in message
...
Hi guys,
I am trying to use the following block of code to insert a function in a
worksheet.
If the VBA Project is not protected, the macro runs just fine, but when
locking the project for viewing, I get the following error:
"Run-time Error 50289 €“ Can't perform operation since the project is
protected"
How can I work it around?
Thanks in advance,
Aldo.

Function CreateProcedureForIndex(Optional wksName As String, Optional
eventName As String, Optional objectName As String)
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long

Const DQUOTE = """" 'one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(Sheets(wksName).CodeName)
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = LineNum + 1: .InsertLines LineNum, "Option Explicit"
LineNum = .CreateEventProc(eventName, objectName) ' + 1
LineNum = LineNum + 1: .InsertLines LineNum, " If
Cells(Target.row, Target.Column + 1).Value = ""Chart Sheet"" Then"
LineNum = LineNum + 1: .InsertLines LineNum, "
Charts(Target.Value).Activate"
LineNum = LineNum + 1: .InsertLines LineNum, " End if"
End With
End Function



All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com