Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default bug with "CodeModule.DeleteLines"

Hi all

Can anybody tell me what's wrong with the following code?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)

ActiveWorkbook.SaveCopyAs ("L:\test1.xls")
Application.EnableEvents = False
Workbooks.Open ("L:\test1.xls")

With Workbooks("test1.xls").VBProject.VBComponents
("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With

Workbooks("test1.xls").Close savechanges:=True
ActiveWorkbook.SaveCopyAs ("L:\test2.xls")
Application.EnableEvents = True

End Sub

I would expect to get two files: test1.xls with the above
code deleted, test2.xls with the code in place. However, I
get two files with the code deleted!

Is there a logical explanation to this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default bug with "CodeModule.DeleteLines"

Hi Claude,

I just tested your code and it works for me exactly as expected. The
test1.xls workbook has no code behind the ThisWorkbook object while the
test2.xls workbook does. Are you sure you aren't doing anything else in your
program that might cause test2.xls to be overwritten or modified?

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Claude" wrote in message
...
Hi all

Can anybody tell me what's wrong with the following code?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)

ActiveWorkbook.SaveCopyAs ("L:\test1.xls")
Application.EnableEvents = False
Workbooks.Open ("L:\test1.xls")

With Workbooks("test1.xls").VBProject.VBComponents
("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With

Workbooks("test1.xls").Close savechanges:=True
ActiveWorkbook.SaveCopyAs ("L:\test2.xls")
Application.EnableEvents = True

End Sub

I would expect to get two files: test1.xls with the above
code deleted, test2.xls with the code in place. However, I
get two files with the code deleted!

Is there a logical explanation to this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default bug with "CodeModule.DeleteLines"

I think you need to change the True to false as below

Workbooks("test1.xls").Close savechanges:=False


--
Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

"Claude" wrote in message
...
Hi all

Can anybody tell me what's wrong with the following code?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)

ActiveWorkbook.SaveCopyAs ("L:\test1.xls")
Application.EnableEvents = False
Workbooks.Open ("L:\test1.xls")

With Workbooks("test1.xls").VBProject.VBComponents
("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With

Workbooks("test1.xls").Close savechanges:=True
ActiveWorkbook.SaveCopyAs ("L:\test2.xls")
Application.EnableEvents = True

End Sub

I would expect to get two files: test1.xls with the above
code deleted, test2.xls with the code in place. However, I
get two files with the code deleted!

Is there a logical explanation to this?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default bug with "CodeModule.DeleteLines"

Hi Bob,
Thanks for the feedback, it's good to know that the code
is OK. Now to try and figure out what else could be
interfering...


-----Original Message-----
Hi Claude,

I just tested your code and it works for me exactly

as expected. The
test1.xls workbook has no code behind the ThisWorkbook

object while the
test2.xls workbook does. Are you sure you aren't doing

anything else in your
program that might cause test2.xls to be overwritten or

modified?

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Claude" wrote in

message
...
Hi all

Can anybody tell me what's wrong with the following

code?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean,
Cancel As Boolean)

ActiveWorkbook.SaveCopyAs ("L:\test1.xls")
Application.EnableEvents = False
Workbooks.Open ("L:\test1.xls")

With Workbooks("test1.xls").VBProject.VBComponents
("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With

Workbooks("test1.xls").Close savechanges:=True
ActiveWorkbook.SaveCopyAs ("L:\test2.xls")
Application.EnableEvents = True

End Sub

I would expect to get two files: test1.xls with the

above
code deleted, test2.xls with the code in place.

However, I
get two files with the code deleted!

Is there a logical explanation to this?



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default bug with "CodeModule.DeleteLines"

Hi Charles,
Thanks for the reply. I want to first clone copies without
code, as a second step save the original file with the
code. However, on saving the code disappears for no
apparent reason!!

-----Original Message-----
I think you need to change the True to false as below

Workbooks("test1.xls").Close savechanges:=False


--
Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

"Claude" wrote in

message
...
Hi all

Can anybody tell me what's wrong with the following

code?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean,
Cancel As Boolean)

ActiveWorkbook.SaveCopyAs ("L:\test1.xls")
Application.EnableEvents = False
Workbooks.Open ("L:\test1.xls")

With Workbooks("test1.xls").VBProject.VBComponents
("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With

Workbooks("test1.xls").Close savechanges:=True
ActiveWorkbook.SaveCopyAs ("L:\test2.xls")
Application.EnableEvents = True

End Sub

I would expect to get two files: test1.xls with the

above
code deleted, test2.xls with the code in place.

However, I
get two files with the code deleted!

Is there a logical explanation to this?



.

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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM


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

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"