Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Importing Modules From Other Workbooks

Here is the code I am using to import modules from other workbooks.
Everything works fine until the opened workbook is closed and the code gets
to "w = Dir()".

Then the "invalid Procedure Call or Argument" error message comes up. I
have tried several adjustments but the most success has been for the code to
Loop and re-open the previous workbook.

I know it's something simple but cannot put my finger on it. Could my "Dim"
statements need some change/addition?

Thanks for any help you can give.

Sub CopyAllModules()
Dim VBComp As VBIDE.VBComponent
Dim FName As String
Dim w As String
w = Dir("H:\*.xls")

Do While w < ""

Workbooks.Open (w)
With Workbooks(w)

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
ThisWorkbook.VBProject.VBComponents.Import FName

Kill FName
End If
Next VBComp
End With
Workbooks(w).Close
w = Dir() ' Error Message "Invalid Procedure Call or Argument"

Loop
End Sub
--
Best wishes,

Jim
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Importing Modules From Other Workbooks

Gary,

Thanks for the response. That didn't work for me either. I did find one
solution, though. I split the macro into two separate ones. The first opens
the workbooks and lists them on a worksheet in the home workbook. It then
passes to the second which imports the modules as listed and closes the
workbooks.

It is strange but the w = Dir() works fine in the standalone "Open
Workbooks" macro. Something in the Import Modules" macro is interfering and
I cannot figure what. At least I did find an alternate solution.

--
Best wishes,

Jim


"Gary Brown" wrote:

I think the state of Excel at the point of...
w = Dir()
is either...
the active workbook has not been saved yet
or
there is no active workbook

Change
w = Dir()
to
w = ""

--
HTH,
Gary Brown

If this post was helpful to you, please select ''YES'' at the bottom of the
post.



"Jim Jackson" wrote:

Here is the code I am using to import modules from other workbooks.
Everything works fine until the opened workbook is closed and the code gets
to "w = Dir()".

Then the "invalid Procedure Call or Argument" error message comes up. I
have tried several adjustments but the most success has been for the code to
Loop and re-open the previous workbook.

I know it's something simple but cannot put my finger on it. Could my "Dim"
statements need some change/addition?

Thanks for any help you can give.

Sub CopyAllModules()
Dim VBComp As VBIDE.VBComponent
Dim FName As String
Dim w As String
w = Dir("H:\*.xls")

Do While w < ""

Workbooks.Open (w)
With Workbooks(w)

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
ThisWorkbook.VBProject.VBComponents.Import FName

Kill FName
End If
Next VBComp
End With
Workbooks(w).Close
w = Dir() ' Error Message "Invalid Procedure Call or Argument"

Loop
End Sub
--
Best wishes,

Jim

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
Importing modules from a folder michaelberrier Excel Discussion (Misc queries) 0 June 25th 06 09:55 PM
Newbie question, XL2003, VBA deleting/adding modules in multiple workbooks KR Excel Programming 6 May 1st 06 08:43 PM
Newbie question: Importing modules (.bas) at startup? Joe Murphy[_4_] Excel Programming 4 June 22nd 04 03:00 AM
Updating VBA Modules and Forms in User Workbooks Joe 90[_2_] Excel Programming 0 April 28th 04 10:23 PM
using forms and modules in multiple workbooks scrabtree23[_2_] Excel Programming 1 November 11th 03 10:57 PM


All times are GMT +1. The time now is 08:41 PM.

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"