![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Hi everyone, I had a problem calling a macro in another book from a macro in my current book before, and got help here with it. I looked up the response, and tried the solution that worked before, but this time i cant get it to work. Help!
This is the code I am trying to run: Dim FromFile As Boolean FromFile = False For Each TestBook In Workbooks If ModuleExists("ShutitDown") = True Then FromFile = True nameworkbook = TestBook.Name Exit For End If Next Application.DisplayAlerts = False Application.Run (nameworkbook) & "!ShutitDown.CloseSave" Application.DisplayAlerts = True The code I'm trying to run is in another open workbook. The procedure is named "CloseSave", and it is located in a module named "ShutitDown". I tried using Application.Run (nameworkbook) & "!CloseSave" instead, but it still is saying it cannot locate the module. I assure you, there is a modeule by this name in a currently open workbook. Thanks [ This Message was edited by: robfo0 on 2002-05-14 16:55 ] |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Would this work?
or
I don't have Excel to test it. HTH |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Mark,
thanks for the response, sorry for the delay, been out of the office for a few days. Neither of these work, still having the same problem of macro not found Any other ideas? |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: May 2002
Posts: 91
|
give the whole path for the workbook
... just a thought |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
No that didnt work either
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Can you post your ModuleExists procedure? I think your problem is with the "ThisWorkbook" contained in that procedure. You should probably re-write it something like this:
Hope this helps, Russell --> So my module is named "basTest", and the procedure I want to run is called "Testupperleft" Also notice the wbk in the ModuleExists procedure - once in the arguments of the function, and again inside the function, this time in place of ThisWorkbook. [ This Message was edited by: Russell Hauf on 2002-05-17 16:49 ] |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Hi Guys :
I don't know if this will help or not but I got this code to work for me ... Please note that My macro has a capital "I" in the name. Code:
Sub SaveAndClose2()
Dim FromFile As Boolean
Dim TestBook As Workbook
FromFile = False
For Each TestBook In Workbooks
For Each VBComp In TestBook.VBProject.VBComponents
'MsgBox (VBComp.Name)
If VBComp.Name = "ShutItDown" Then
FromFile = True
nameworkbook = TestBook.Name
Exit For
End If
Next VBComp
Next
Application.DisplayAlerts = False
Application.Run (nameworkbook) & "!ShutItDown.CloseSave"
Application.DisplayAlerts = True
http://<a href="http://www.cpearson....el/vbe.htm</a> |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
This is a follow up post. Thanks everyone for your posts, but i tried them ALL and none worked. After weeks of trying to figure it out! alas!!! Here is the way that worked for me:
Application.Run "'" & nameworkbook & "'!ShutitDown.CloseSave" I guess it needs the stupid ' !!! Hope this helps someone else, because it was hell trying to figure it out |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|