Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Macro in ThisWorkbook Orion Cochrane Excel Programming 4 October 30th 08 06:10 PM
Programmatically removing data filters PatK Excel Programming 12 August 14th 08 12:09 AM
Removing Add-ins programmatically from Excel 2003 using VBScript Dutch Gemini Excel Programming 3 August 30th 05 03:00 PM
Remove ThisWorkbook code via VBA PCLIVE Excel Programming 3 August 8th 05 09:31 PM
Removing Checkboxes Programmatically Mark D'Agosta Excel Programming 4 October 21st 03 03:57 PM


All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"