PC Review


Reply
Thread Tools Rate Thread

Delete all code in VBA module - error?

 
 
Matt
Guest
Posts: n/a
 
      16th Jan 2007
I am trying to use the code:

Sub delete_all_code (module_name)

Dim VBCodeMod as VBComponent
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents(module_name)CodeModule
With VBCodeMod
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With

End Sub

(taken from G.Groups many years ago)

that has worked for me with no problems in the past. I think I was
using excel 2000 when I first used this.

I am now using excel 2003, and i have the VBA Extensibility reference
'activated' . Have also tried unchecking this and using 'Dim VBCodeMod
as Object' with no success.

When I try to run this I get the following error:

Run-time error '1004':

Method 'VBProject' of Object '_Workbook' failed

Any ideas as to how I can get this to work or any other way of deleting
either:

1 - all the code in an excel VBA module
or
2 - the entire VBA module (preferable)

for a given module.

Many thanks in advance for any help!

Matt

 
Reply With Quote
 
 
 
 
Matt
Guest
Posts: n/a
 
      16th Jan 2007
Thanks, this works fine now on my computer!

BUT

This is part of an application that will be rolled out across multiple
(20+) analysts (the VBA code needs deleting as the output will get sent
to clients) who may not have their security set to this. Is there a
way of changing this setting using VBA or will they just have to change
their own settings?

Thanks

Matt


Jim Thomlinson wrote:
> You may need to change your security. Select Tools -> Macros -> Security ->
> Trusted Sources (Tab) -> Trust Access to Visual Basic Projects
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Matt" wrote:
>
> > I am trying to use the code:
> >
> > Sub delete_all_code (module_name)
> >
> > Dim VBCodeMod as VBComponent
> > Dim StartLine As Long
> > Dim HowManyLines As Long
> >
> > Set VBCodeMod =
> > ThisWorkbook.VBProject.VBComponents(module_name)CodeModule
> > With VBCodeMod
> > StartLine = 1
> > HowManyLines = .CountOfLines
> > .DeleteLines StartLine, HowManyLines
> > End With
> >
> > End Sub
> >
> > (taken from G.Groups many years ago)
> >
> > that has worked for me with no problems in the past. I think I was
> > using excel 2000 when I first used this.
> >
> > I am now using excel 2003, and i have the VBA Extensibility reference
> > 'activated' . Have also tried unchecking this and using 'Dim VBCodeMod
> > as Object' with no success.
> >
> > When I try to run this I get the following error:
> >
> > Run-time error '1004':
> >
> > Method 'VBProject' of Object '_Workbook' failed
> >
> > Any ideas as to how I can get this to work or any other way of deleting
> > either:
> >
> > 1 - all the code in an excel VBA module
> > or
> > 2 - the entire VBA module (preferable)
> >
> > for a given module.
> >
> > Many thanks in advance for any help!
> >
> > Matt
> >
> >


 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      16th Jan 2007
Hi Matt

Not possible to change it but you can see if it is checked
See this page
http://www.j-walk.com/ss/excel/tips/tip96.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Matt" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Thanks, this works fine now on my computer!
>
> BUT
>
> This is part of an application that will be rolled out across multiple
> (20+) analysts (the VBA code needs deleting as the output will get sent
> to clients) who may not have their security set to this. Is there a
> way of changing this setting using VBA or will they just have to change
> their own settings?
>
> Thanks
>
> Matt
>
>
> Jim Thomlinson wrote:
>> You may need to change your security. Select Tools -> Macros -> Security ->
>> Trusted Sources (Tab) -> Trust Access to Visual Basic Projects
>> --
>> HTH...
>>
>> Jim Thomlinson
>>
>>
>> "Matt" wrote:
>>
>> > I am trying to use the code:
>> >
>> > Sub delete_all_code (module_name)
>> >
>> > Dim VBCodeMod as VBComponent
>> > Dim StartLine As Long
>> > Dim HowManyLines As Long
>> >
>> > Set VBCodeMod =
>> > ThisWorkbook.VBProject.VBComponents(module_name)CodeModule
>> > With VBCodeMod
>> > StartLine = 1
>> > HowManyLines = .CountOfLines
>> > .DeleteLines StartLine, HowManyLines
>> > End With
>> >
>> > End Sub
>> >
>> > (taken from G.Groups many years ago)
>> >
>> > that has worked for me with no problems in the past. I think I was
>> > using excel 2000 when I first used this.
>> >
>> > I am now using excel 2003, and i have the VBA Extensibility reference
>> > 'activated' . Have also tried unchecking this and using 'Dim VBCodeMod
>> > as Object' with no success.
>> >
>> > When I try to run this I get the following error:
>> >
>> > Run-time error '1004':
>> >
>> > Method 'VBProject' of Object '_Workbook' failed
>> >
>> > Any ideas as to how I can get this to work or any other way of deleting
>> > either:
>> >
>> > 1 - all the code in an excel VBA module
>> > or
>> > 2 - the entire VBA module (preferable)
>> >
>> > for a given module.
>> >
>> > Many thanks in advance for any help!
>> >
>> > Matt
>> >
>> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
#NAME error on all VBA module code Philip Mark Hunt Microsoft Excel Programming 8 21st Jul 2009 04:23 PM
code to delete module / macro in another file Ray Clark Microsoft Excel Misc 1 3rd Jul 2008 04:15 AM
Compile error in hidden module: NT Reg Code =?Utf-8?B?Tmlja3kgWmVl?= Microsoft Excel Discussion 1 20th Jun 2006 07:27 AM
error when running Select..Into within code module =?Utf-8?B?QmVu?= Microsoft Access VBA Modules 1 18th Feb 2006 05:57 PM
How to delete a code module Peter Brase Microsoft Access Form Coding 1 16th Mar 2004 08:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 PM.