Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extra Basic App Question 2

Status
Not open for further replies.

RPEN

Programmer
Aug 23, 2007
33
CA
Here's my problem:

I am creating a drop down list by searching through several folders for any macros that are stored there. The macros are stored in an array and then presented via a dropdown list. The user then picks one of the macros from the list.

I then take the name of the macro that was selected and use the Shell command to run the macro:


Code:
macroname = "ebrun.exe " + Filenames(FileChosen)
rc& = Shell (macroname,4)

The problem is that I can't use $Include in the macros that are run via the Shell command. I want to include a header file that contains global variables. If I add the Include, the macro doesn't run. Without the Include, it works fine.

Anyone know why this is, or how I can run the macro without using the Shell command?
 
What error messages, if any, are you getting when you include the header file?

Have you tried attaching a simple header file?

How did you create the .EBH file? Did you copy an existing .EBM file, change its file extension and entered the header code? If so, this may be the problem. Create a new text document, change .txt to .ebh and copy the "corrupt" header code over, or go to File -> New -> Header in the Macro Editor and copy over the code.
 
It's an existing ebh that's used in other places. It looks to me like the problem is that it's running the macro via the Shell command and the $Include just doesn't work in that scenario.

I get this message:

"Macro failed to begin execution.
 
What errors are showing, or what happens when you debug in the Macro Editor?
 
The code below works for me.

Macro_1.ebm
Code:
Sub Main()
   Dim macro_name As String, rc As Long
   
   macro_name = "ebrun.exe " + "Macro_2.ebm"
   rc = Shell(macro_name, 4)
End Sub

Macro_2.ebm
Code:
'$Include "C:\Program Files\Attachmate\EXTRA!\Macros\Modules\Header.EBH"

Sub Main()
   Print_Header
End Sub

Header.ebm
Code:
Sub Print_Header
   Msgbox "This is the Header file."
End Sub
 
That looks very similar to the code I'm running. I'll have another look tomorrow to see if I can get it to work.

Thanks.
 
The problem seems to be that I was using UNC path names:

eg: '$Include "\\Iglanfs2\Penner1$\CAT\Apps\CAT.ebh"

When I change it to point to my C: drive it works.

eg: '$Include "C:\CAT\Apps\CAT.ebh"


Any idea why??

When running a macro via the Shell command, is it possible to pass a variable to the called macro?

Thanks for the help.
 
thread1-1237638

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Make sure you have access to the UNC path.

Start -> Run -> \\Iglanfs2\Penner1$\CAT\Apps\CAT.ebh

When running a macro via the Shell command, is it possible to pass a variable to the called macro?

Macro_1.ebm
Code:
Sub Main()
   Dim rc As Long, macro_name As String, argument As String

   argument = "an argument"
   macro_name = "ebrun.exe " & "Macro_2.ebm " & argument
   
   rc = Shell(macro_name, 4)
End Sub

Macro_2.ebm
Code:
Sub Main()
   MsgBox Command$   ' Prints argument
End Sub
 
Thanks, that works, although I'm trying to pass a path and
it doesn't seem to like the backslash.

This doesn't work:

foldername = "\\Iglanfs2\Penner1$\CAT\"
macroname = "ebrun.exe " + Filenames(FileChosen) + " " + foldername
rc& = Shell (macroname,4)

What I'm trying to avoid is hard coding the full pathnames in all of my macros so that I can move my entire folder structure to another location and make minimal changes in order to get it working in the new location.

I have to run the macros via the Shell command so that Global variables are not really an option.

Ideas?
 
Macro_1.ebm
Code:
Sub Main()
   Dim rc As Long, folder_name As String, macro_name As String

   folder_name = "\\Iglanfs2\Penner1$\CAT"
   macro_name = "ebrun.exe " & chr(34) & "Macro_2.ebm" & chr(34) & folder_name   
   rc = Shell(macro_name, 4)
End Sub
 
Works for me.
Code:
'macro1
Global gMyFolderPath

Sub Main()

   gMyFolderPath = "C:\"
   rc = Shell("ebrun.exe C:\Macro2.ebm",4) 
   
End Sub
Code:
'macro2
Global gMyFolderPath

Sub Main()

    Dim ShellMe as String

    ShellMe = "ebrun.exe " & gMyFolderPath & "Macro3.ebm"
    rc = Shell(ShellMe,4) 
    
End Sub
Code:
'macro3
Global gMyFolderPath

Sub Main()
      MSGBOX "Sucess"
End Sub

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Mr.Milson, thanks. Should this also work if I use Global Const?

eg: Global Const gMyFolderPath = "C:\"

When I try to assign it this way it doesn't run. When I use your method of assigning within the macro it works.
 
Not sure haven't tried it with Global Const.


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top