ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically removing code from ThisWorkbook XL2007 (https://www.excelbanter.com/excel-programming/424187-programmatically-removing-code-thisworkbook-xl2007.html)

PCLIVE

Programmatically removing code from ThisWorkbook XL2007
 
I'm still having some trouble with the code below. It previously worked in
XL2002 and earlier. However, there were some issues on some installations
of XL2003 and now consistant errors on XL2007.
The error occurs on line, "Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule"

If I attempt to step through the code, it just gives you an error stating,
"Run-time error '1004': Application-defined or object-defined error"

If I initiate this code from the button-click as intended, then I get the
"Run-time error '1004': Programmatic access to Visual Basic Project is
not trusted"

Is there a way to achieve what I want in XL2007?

Thanks,
Paul


Private Sub CommandButton1_Click()
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim ProcLen As Long

Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With CodeMod
StartLine = .ProcStartLine("Workbook_Open", vbext_pk_Proc)
ProcLen = .ProcCountLines("Workbook_Open", vbext_pk_Proc)
.DeleteLines StartLine, ProcLen
End With

End Sub

--




Chip Pearson

Programmatically removing code from ThisWorkbook XL2007
 
On the Office button, choose "Excel Options" then the "Trust Center"
page. There, click the "Trust Center Settings" button. Choose the
"Macro Setting" page and check the "Trust access to the VBA project
object model".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 16 Feb 2009 10:52:52 -0500, "PCLIVE"
wrote:

I'm still having some trouble with the code below. It previously worked in
XL2002 and earlier. However, there were some issues on some installations
of XL2003 and now consistant errors on XL2007.
The error occurs on line, "Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook ").CodeModule"

If I attempt to step through the code, it just gives you an error stating,
"Run-time error '1004': Application-defined or object-defined error"

If I initiate this code from the button-click as intended, then I get the
"Run-time error '1004': Programmatic access to Visual Basic Project is
not trusted"

Is there a way to achieve what I want in XL2007?

Thanks,
Paul


Private Sub CommandButton1_Click()
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim ProcLen As Long

Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook ").CodeModule
With CodeMod
StartLine = .ProcStartLine("Workbook_Open", vbext_pk_Proc)
ProcLen = .ProcCountLines("Workbook_Open", vbext_pk_Proc)
.DeleteLines StartLine, ProcLen
End With

End Sub


PCLIVE

Programmatically removing code from ThisWorkbook XL2007
 
Thanks Chip. That was it.



--

"Chip Pearson" wrote in message
...
On the Office button, choose "Excel Options" then the "Trust Center"
page. There, click the "Trust Center Settings" button. Choose the
"Macro Setting" page and check the "Trust access to the VBA project
object model".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 16 Feb 2009 10:52:52 -0500, "PCLIVE"
wrote:

I'm still having some trouble with the code below. It previously worked
in
XL2002 and earlier. However, there were some issues on some installations
of XL2003 and now consistant errors on XL2007.
The error occurs on line, "Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule"

If I attempt to step through the code, it just gives you an error stating,
"Run-time error '1004': Application-defined or object-defined error"

If I initiate this code from the button-click as intended, then I get the
"Run-time error '1004': Programmatic access to Visual Basic Project is
not trusted"

Is there a way to achieve what I want in XL2007?

Thanks,
Paul


Private Sub CommandButton1_Click()
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim ProcLen As Long

Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
With CodeMod
StartLine = .ProcStartLine("Workbook_Open", vbext_pk_Proc)
ProcLen = .ProcCountLines("Workbook_Open", vbext_pk_Proc)
.DeleteLines StartLine, ProcLen
End With

End Sub





All times are GMT +1. The time now is 11:37 PM.

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