Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KR KR is offline
external usenet poster
 
Posts: 121
Default List all modules in workbook X?

This is probably an easy one, I just don't know the commands to use- I'm
looping through a series of workbooks, and need to identify the module names
in each.

If possible, it would be really, really helpful to know when each module was
last updated- in some cases there are modules with the same name, some of
which were imported replacements for older (broken) code, so if I can figure
out which workbooks have that module /and/ which ones are the old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default List all modules in workbook X?

The following code will list all the modules in the
ActiveWorkbook. There is no way to determine when a module was
last modifed.


"KR" wrote in message
...
This is probably an easy one, I just don't know the commands to
use- I'm
looping through a series of workbooks, and need to identify the
module names
in each.

If possible, it would be really, really helpful to know when
each module was
last updated- in some cases there are modules with the same
name, some of
which were imported replacements for older (broken) code, so if
I can figure
out which workbooks have that module /and/ which ones are the
old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default List all modules in workbook X?

The following code will list all the modules in the
ActiveWorkbook. There is no way to determine when a module was
last modified.

Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
Debug.Print VBComp.Name
End If
Next VBComp

You'll need a reference to the Extensibility library. In VBA, go
to the Tools menu, choose References, and scroll down to
"Microsoft Visual Basic For Application Extensibility Library"
and put a check next to it.

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




"KR" wrote in message
...
This is probably an easy one, I just don't know the commands to
use- I'm
looping through a series of workbooks, and need to identify the
module names
in each.

If possible, it would be really, really helpful to know when
each module was
last updated- in some cases there are modules with the same
name, some of
which were imported replacements for older (broken) code, so if
I can figure
out which workbooks have that module /and/ which ones are the
old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith




  #4   Report Post  
Posted to microsoft.public.excel.programming
KR KR is offline
external usenet poster
 
Posts: 121
Default List all modules in workbook X?

Chip-

Thanks for the snippet, I'll give it a try.

Just curious, is there a way to pull in a specific line of code? Since I
know which module was modified, if I could pull in, for example, the 15th
line in that module, then I could compare it against the 15th line in the
modified (new) module to see if it matches up. It wouldn't require a date
but would still allow me to detect outdated modules. Any suggestions on how
I might go about this?

Many (many many) thanks,
Keith


"Chip Pearson" wrote in message
...
The following code will list all the modules in the
ActiveWorkbook. There is no way to determine when a module was
last modified.

Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
Debug.Print VBComp.Name
End If
Next VBComp

You'll need a reference to the Extensibility library. In VBA, go
to the Tools menu, choose References, and scroll down to
"Microsoft Visual Basic For Application Extensibility Library"
and put a check next to it.

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




"KR" wrote in message
...
This is probably an easy one, I just don't know the commands to
use- I'm
looping through a series of workbooks, and need to identify the
module names
in each.

If possible, it would be really, really helpful to know when
each module was
last updated- in some cases there are modules with the same
name, some of
which were imported replacements for older (broken) code, so if
I can figure
out which workbooks have that module /and/ which ones are the
old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default List all modules in workbook X?

Keith

Dim CodeLine As String
Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
CodeLine = VBComp.CodeModule.Lines(15, 1)
Debug.Print CodeLine
End If
Next VBComp

See www.cpearson.com/excel/vbe.htm for details about working with
the Extensibility libary.


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



"KR" wrote in message
...
Chip-

Thanks for the snippet, I'll give it a try.

Just curious, is there a way to pull in a specific line of
code? Since I
know which module was modified, if I could pull in, for
example, the 15th
line in that module, then I could compare it against the 15th
line in the
modified (new) module to see if it matches up. It wouldn't
require a date
but would still allow me to detect outdated modules. Any
suggestions on how
I might go about this?

Many (many many) thanks,
Keith


"Chip Pearson" wrote in message
...
The following code will list all the modules in the
ActiveWorkbook. There is no way to determine when a module was
last modified.

Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
Debug.Print VBComp.Name
End If
Next VBComp

You'll need a reference to the Extensibility library. In VBA,
go
to the Tools menu, choose References, and scroll down to
"Microsoft Visual Basic For Application Extensibility Library"
and put a check next to it.

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




"KR" wrote in message
...
This is probably an easy one, I just don't know the commands
to
use- I'm
looping through a series of workbooks, and need to identify
the
module names
in each.

If possible, it would be really, really helpful to know when
each module was
last updated- in some cases there are modules with the same
name, some of
which were imported replacements for older (broken) code, so
if
I can figure
out which workbooks have that module /and/ which ones are
the
old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith










  #6   Report Post  
Posted to microsoft.public.excel.programming
KR KR is offline
external usenet poster
 
Posts: 121
Default List all modules in workbook X?

Chip (or others)-

I thought I had this code working, but now I'm getting a weird error- the
relevant code is below. The first workbook opens, then I get a pop-up error:
Run time error '-2147024890 (80070006)': System Error
&H80070006(-2147024890). The handle is invalid.

When I look in the code (debug) and mouseover to get the VBComp.Type the
mouseover box shows: VBComp.Type = <Method 'type' of object '_vbComponent'
failed and it actually errored out on the "if VBComp.Name..." statement.
I'm way out of my league here... I have added the iserror(VBComp.type) to
try to just bypass this and keep the workbook going, but it still bugs
out...

Any help would be greatly appreciated!
Thanks,
Keith

<snipped code that gets all workbook names in directory and adds them to
MyFiles()
If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)

'lets me verify how many workbooks have been processed
Application.StatusBar = "Processing " & Fnum & " of " &
UBound(MyFiles) & " - " & MyFiles(Fnum)

'open as readonly, called "mybook"
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum), 0, False)
Application.EnableEvents = True

For Each VBComp In mybook.VBProject.VBComponents
If IsError(VBComp.Type) Then
'do nothing
Else
If VBComp.Type = vbext_ct_StdModule Then
'MsgBox VBComp.Name

If VBComp.Name = "ValidateAndPasteData1" Then
mybook.VBProject.VBComponents.Remove VBComp

If VBComp.Name = "ValidateAndPasteData" Then
(etc.)

"Chip Pearson" wrote in message
...
Keith

Dim CodeLine As String
Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
CodeLine = VBComp.CodeModule.Lines(15, 1)
Debug.Print CodeLine
End If
Next VBComp

See www.cpearson.com/excel/vbe.htm for details about working with
the Extensibility libary.


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



"KR" wrote in message
...
Chip-

Thanks for the snippet, I'll give it a try.

Just curious, is there a way to pull in a specific line of
code? Since I
know which module was modified, if I could pull in, for
example, the 15th
line in that module, then I could compare it against the 15th
line in the
modified (new) module to see if it matches up. It wouldn't
require a date
but would still allow me to detect outdated modules. Any
suggestions on how
I might go about this?

Many (many many) thanks,
Keith


"Chip Pearson" wrote in message
...
The following code will list all the modules in the
ActiveWorkbook. There is no way to determine when a module was
last modified.

Dim VBComp As VBIDE.VBComponent
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
Debug.Print VBComp.Name
End If
Next VBComp

You'll need a reference to the Extensibility library. In VBA,
go
to the Tools menu, choose References, and scroll down to
"Microsoft Visual Basic For Application Extensibility Library"
and put a check next to it.

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




"KR" wrote in message
...
This is probably an easy one, I just don't know the commands
to
use- I'm
looping through a series of workbooks, and need to identify
the
module names
in each.

If possible, it would be really, really helpful to know when
each module was
last updated- in some cases there are modules with the same
name, some of
which were imported replacements for older (broken) code, so
if
I can figure
out which workbooks have that module /and/ which ones are
the
old ones that
still need to be replaced, that would be very, very cool.

Thanks for any help or advice,
Keith










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
copying modules from one workbook to another workbook Vinod[_2_] Excel Discussion (Misc queries) 3 September 19th 08 06:18 PM
Automatically Delete WorkBook 2 modules by using Workbook 1 module ddiicc Excel Programming 5 July 27th 05 12:53 PM
Extracting (copying) modules from one workbook to another. Devin Linnington Excel Programming 1 July 6th 05 11:59 PM
Copy Modules from One workbook to Active Workbook Jim Gifford Excel Programming 1 November 18th 03 12:30 PM
How to Compare Workbook VBA modules Dan[_26_] Excel Programming 2 October 16th 03 12:59 PM


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