Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Explanation needed for CopyAllModules code


Thanks to David McRitchie, I was able to deploy the following Chip
Pearson's code to import code modules (complete with their denizen of
procedures) from one workbook to my Personal workbook project. It
worked like charm!

Still in the glow of my delight, I have spent some hours trying to
figure out the logic of "killing" the Filename (FName) both prior to
exporting and importing. Could someone kindly shed some light on this.
I am baffled. (Below is the code).




Sub CopyAllModules()

Dim FName As String
Dim VBComp As VBIDE.VBComponent

With Workbooks("Storer")
FName = .Path & "\code.txt"
If Dir(FName) < "" Then
*Kill FName*
End If
For Each VBComp In .VBProject.VBComponents
If VBComp.Type < vbext_ct_Document Then
VBComp.Export FName
Workbooks("Personal").VBProject.VBComponents.Impor t FName
* Kill FName*
End If
Next VBComp
End With

End Sub


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=386689

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Explanation needed for CopyAllModules code

In this case, I think the first "kill" was unnecessary. When I tested in xl2003
(under winXP), if the code.txt file existed, it was overwritten.

It looks like Chip just wanted to make sure that the file was gone--just in
case...

On the other hand, the second "kill" is nice. It cleans up after itself. But
since exporting will overwrite the existing file, the Kill could have been used
just once at the end of the routine (right before the "end sub" line).


davidm wrote:

Thanks to David McRitchie, I was able to deploy the following Chip
Pearson's code to import code modules (complete with their denizen of
procedures) from one workbook to my Personal workbook project. It
worked like charm!

Still in the glow of my delight, I have spent some hours trying to
figure out the logic of "killing" the Filename (FName) both prior to
exporting and importing. Could someone kindly shed some light on this.
I am baffled. (Below is the code).

Sub CopyAllModules()

Dim FName As String
Dim VBComp As VBIDE.VBComponent

With Workbooks("Storer")
FName = .Path & "\code.txt"
If Dir(FName) < "" Then
*Kill FName*
End If
For Each VBComp In .VBProject.VBComponents
If VBComp.Type < vbext_ct_Document Then
VBComp.Export FName
Workbooks("Personal").VBProject.VBComponents.Impor t FName
* Kill FName*
End If
Next VBComp
End With

End Sub

--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=386689


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Explanation needed for CopyAllModules code


Thanks, Dave for being so obliging. I am still not a bit confused
Regarding the first *KILL*, my query is: why kill the filename (or hav
it overwritten) and yet in the next move export same? May be I am no
fully appreciating what the "code txt.file" is. Further light, Dave

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=38668

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Explanation needed for CopyAllModules code

Chip is a belt and suspenders type person.

He wants to make sure that there is no file with that name. In my tests, it
didn't matter. The existing file was overwritten.

And if you step through your code against a test workbook, you can open that
code.txt file. You can see it contains the code of each of your modules.

Just like if you rightclicked on the module and hit "export file".

davidm wrote:

Thanks, Dave for being so obliging. I am still not a bit confused.
Regarding the first *KILL*, my query is: why kill the filename (or have
it overwritten) and yet in the next move export same? May be I am not
fully appreciating what the "code txt.file" is. Further light, Dave.

--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=386689


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Explanation needed for CopyAllModules code

Chip is a belt and suspenders type person.

It comes from years of programming on fault tolerant Tandem
systems.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Dave Peterson" wrote in message
...
Chip is a belt and suspenders type person.

He wants to make sure that there is no file with that name. In
my tests, it
didn't matter. The existing file was overwritten.

And if you step through your code against a test workbook, you
can open that
code.txt file. You can see it contains the code of each of
your modules.

Just like if you rightclicked on the module and hit "export
file".

davidm wrote:

Thanks, Dave for being so obliging. I am still not a bit
confused.
Regarding the first *KILL*, my query is: why kill the filename
(or have
it overwritten) and yet in the next move export same? May be I
am not
fully appreciating what the "code txt.file" is. Further
light, Dave.

--
davidm
------------------------------------------------------------------------
davidm's Profile:
http://www.excelforum.com/member.php...o&userid=20645
View this thread:
http://www.excelforum.com/showthread...hreadid=386689


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Explanation needed for CopyAllModules code

It seems very reasonable inside VBA, too.

Chip Pearson wrote:

Chip is a belt and suspenders type person.


It comes from years of programming on fault tolerant Tandem
systems.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Dave Peterson" wrote in message
...
Chip is a belt and suspenders type person.

He wants to make sure that there is no file with that name. In
my tests, it
didn't matter. The existing file was overwritten.

And if you step through your code against a test workbook, you
can open that
code.txt file. You can see it contains the code of each of
your modules.

Just like if you rightclicked on the module and hit "export
file".

davidm wrote:

Thanks, Dave for being so obliging. I am still not a bit
confused.
Regarding the first *KILL*, my query is: why kill the filename
(or have
it overwritten) and yet in the next move export same? May be I
am not
fully appreciating what the "code txt.file" is. Further
light, Dave.

--
davidm
------------------------------------------------------------------------
davidm's Profile:
http://www.excelforum.com/member.php...o&userid=20645
View this thread:
http://www.excelforum.com/showthread...hreadid=386689


--

Dave Peterson


--

Dave Peterson
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
Code Needed John Calder New Users to Excel 10 July 15th 09 11:42 PM
Help needed with VBA code Sam Hill Excel Discussion (Misc queries) 1 May 9th 06 02:29 PM
Better code needed ceplane Excel Programming 6 May 10th 04 07:59 PM
Explanation of code Matt Excel Programming 3 January 15th 04 12:12 PM
Explanation of code marksuza Excel Programming 2 November 21st 03 11:45 AM


All times are GMT +1. The time now is 12:13 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"