Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete modules programmatically and save

HI,

I have hit a wall here. I delete some modules using VBComponents.Remove.
After that, even if I save the workbook using Save method, the changes are
not saved. Does anyone has a clue? After I run the macro below it still asks
me if I want to save the changes when i close the workbook. Note the macro
to delete the modules is in the same workbook. So the macro is trying to
delete itself too.

Code

Dim obj As Object
Dim VBComps As Variant

Set VBComps = ThisWorkbook.VBProject.VBComponents

For Each obj In VBComps
If obj.Type = 1 Or obj.Type = 2 Then
VBComps.Remove obj
End If
Next

ThisWorkbook.Save

Thanks in advance,

Brij


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete modules programmatically and save

You can't save in the same macro that did the deletion. The deletion
doesn't actually take place until the macro ends.

In the macro, use application.Ontime to run a sum that saves the workbook

application.Ontime now,"MacroToSaveWorkbook"

This allows the code to end and then the save is performed.

--
Regards,
Tom Ogilvy

Brijesh Shah wrote in message
...
HI,

I have hit a wall here. I delete some modules using VBComponents.Remove.
After that, even if I save the workbook using Save method, the changes are
not saved. Does anyone has a clue? After I run the macro below it still

asks
me if I want to save the changes when i close the workbook. Note the macro
to delete the modules is in the same workbook. So the macro is trying to
delete itself too.

Code

Dim obj As Object
Dim VBComps As Variant

Set VBComps = ThisWorkbook.VBProject.VBComponents

For Each obj In VBComps
If obj.Type = 1 Or obj.Type = 2 Then
VBComps.Remove obj
End If
Next

ThisWorkbook.Save

Thanks in advance,

Brij




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete modules programmatically and save

Tom,

Thanks for the reply

This may sound naive, but where do i but the macro to save the workbook. I
am new to formula stuff in Excel.

My goal is to delete all macros from the workbook so that the user is not
prompted to disable or enable macros (based on security settings) when
he/she opens the workbook. Is there a way to put a formula in a cell that
would save the workbook later using Application.Ontime?

Thanks again.

Brij

"Tom Ogilvy" wrote in message
...
You can't save in the same macro that did the deletion. The deletion
doesn't actually take place until the macro ends.

In the macro, use application.Ontime to run a sum that saves the workbook

application.Ontime now,"MacroToSaveWorkbook"

This allows the code to end and then the save is performed.

--
Regards,
Tom Ogilvy

Brijesh Shah wrote in message
...
HI,

I have hit a wall here. I delete some modules using VBComponents.Remove.
After that, even if I save the workbook using Save method, the changes

are
not saved. Does anyone has a clue? After I run the macro below it still

asks
me if I want to save the changes when i close the workbook. Note the

macro
to delete the modules is in the same workbook. So the macro is trying to
delete itself too.

Code

Dim obj As Object
Dim VBComps As Variant

Set VBComps = ThisWorkbook.VBProject.VBComponents

For Each obj In VBComps
If obj.Type = 1 Or obj.Type = 2 Then
VBComps.Remove obj
End If
Next

ThisWorkbook.Save

Thanks in advance,

Brij






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete modules programmatically and save

I would put the code in a separate workbook to start with - that avoids the
problem of having to delete it.

I don't know what you are doing or what is feasible/consistent with what you
are doing, so I really can't suggest what the best way to proceed it.

--
Regards,
Tom Ogilvy

Brijesh Shah wrote in message
...
Tom,

Thanks for the reply

This may sound naive, but where do i but the macro to save the workbook. I
am new to formula stuff in Excel.

My goal is to delete all macros from the workbook so that the user is not
prompted to disable or enable macros (based on security settings) when
he/she opens the workbook. Is there a way to put a formula in a cell that
would save the workbook later using Application.Ontime?

Thanks again.

Brij

"Tom Ogilvy" wrote in message
...
You can't save in the same macro that did the deletion. The deletion
doesn't actually take place until the macro ends.

In the macro, use application.Ontime to run a sum that saves the

workbook

application.Ontime now,"MacroToSaveWorkbook"

This allows the code to end and then the save is performed.

--
Regards,
Tom Ogilvy

Brijesh Shah wrote in message
...
HI,

I have hit a wall here. I delete some modules using

VBComponents.Remove.
After that, even if I save the workbook using Save method, the changes

are
not saved. Does anyone has a clue? After I run the macro below it

still
asks
me if I want to save the changes when i close the workbook. Note the

macro
to delete the modules is in the same workbook. So the macro is trying

to
delete itself too.

Code

Dim obj As Object
Dim VBComps As Variant

Set VBComps = ThisWorkbook.VBProject.VBComponents

For Each obj In VBComps
If obj.Type = 1 Or obj.Type = 2 Then
VBComps.Remove obj
End If
Next

ThisWorkbook.Save

Thanks in advance,

Brij








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
Visual Basic Protection and Delete Modules Jeremy Excel Discussion (Misc queries) 3 April 27th 10 02:32 PM
How to delete lines programmatically if a condition is met? nt_artagnian[_2_] Excel Discussion (Misc queries) 1 March 7th 07 05:39 PM
Delete Code Modules Programatically blatham Excel Discussion (Misc queries) 1 February 3rd 06 05:38 PM
Delete Modules and Userforms Peter Pantus Excel Programming 1 September 26th 03 08:17 PM
Excel VBA Programmatically delete a form? Anthony Keefe Excel Programming 0 August 30th 03 10:03 PM


All times are GMT +1. The time now is 10:07 AM.

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

About Us

"It's about Microsoft Excel"