Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 -- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Removing Macro in ThisWorkbook | Excel Programming | |||
Programmatically removing data filters | Excel Programming | |||
Removing Add-ins programmatically from Excel 2003 using VBScript | Excel Programming | |||
Remove ThisWorkbook code via VBA | Excel Programming | |||
Removing Checkboxes Programmatically | Excel Programming |