list all macro names in macro

A

abbarition

I am adding modules into an existing database that is
maintained by someone who doesn't know (and has no
interest in knowing) VB. I am setting up a new form that
will allow them to easily add additional items and it
will run my code based off the values in the form's
RecordSource (a table).

After it runs my code, it will need to run a macro that
the database's creator will write. They always enter the
different macros for this process in one macro with
different macro names. I would like to create a list box
on my form that will be populated with the different
macro names in this macro so they can choose the macro
name to run. I tried using the CurrentProject.AllMacros,
but it only shows me the macro and not all the macro
names inside the macro.

The database creator will not make any changes in VB (no
matter how simple) and they will feel like they are
losing control of the database by asking me to make
changes in the code. If I can set it up so they can
choose the macro name, they will still feel like they are
in control of the database and will be much more open to
these new VB changes that are really needed!
 
G

Guest

I have been trying to find out the exact same info for the past 3 weeks... no
luck. If you find out, I would very much like to know.

good luck.
 
G

Guest

Please let me clarify this so I better understand your question.

You want to grab each line inside of each MS Access macro.

Is this correct?

Thank you,
Jeff Young
 
G

Guest

Please let me clarify this so I better understand your question.

You want to grab each line inside of each MS Access macro.

Is this correct?

Thank you,
Jeff Young
 
M

M.L. Sco Scofield

There is no "easy" way to list all of the macro names inside of a macro
group. You have to jump through a couple of hoops.

I know someone that has done this. I'll see if I can get him to come over
here and share his knowledge.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
J

Jeff Conrad

Master Sco has buzzed me.

Just as Sco says, getting a list of all the internal macro
names is not as simple as you may think. This particular
area was THE major stumbling block for me in a soon-
to-be released Add-In.

In a nutshell you will need to do the following to make this work:
1. First check to see if the macro was deleted. Otherwise
it will show up as a temp object
2. Check to see if the macro is hidden AND if the user has
set their properties to not show hidden objects.
3. Create a temp file in the user's Temp directory
4. Export out each macro using the SaveAsText option to the
temp file.
5. Go through the entire text file and grab all the necessary
internal macro names. While doing this, strip out all the
unnecessary stuff and format it just like it would be presented
in the Event Procedures (MacroName.InternalName, etc.)
A semicolon must also be added in between each name.
6. Close the temp file.
7. Continue looping through each macro in the Container
and do the same thing.
8. Do the final formatting to present the completed list
of macro groups and internal names.
9. Delete the temp file in the user's Temp directory.
10. Stuff the completed list into a combo box (in my case)
or into a list box.

Got it?
:)

And for the record, this was a joint mission to come up with
the completed code. Don't let Sco fool you, HE was the one
that did most of the work. I could probably post the code,
but I will need to get Sco's permission first since it was his
work as well. Also, the particular code I have has different
versions for 97 and 2K+. It does not HAVE to be different,
but it is integrated into other parts of the add-in. I will have
to strip it out and do some quick testing first.
 
M

M.L. Sco Scofield

Grasshopper,

Share away...

:)

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
J

Jeff Conrad

Master,

I pulled out the necessary code, did some extra
cleanup, modifying, and testing to make sure
everything was OK.

I was mistaken about the difference in code versions.
I forgot that the Application.GetHiddenAttribute
was not added until 2000. So The code does differ
between 97 and 2K+.

Should I make one post for the 97 code and one for the
2K+ code or throw it all into one post? It might get
confusing in one post.
 
M

M.L. Sco Scofield

Well Grasshopper,

Here's what I'd do. I'd ask "abbarition" what version of Access he (she) is
using. After all, he (she) should have said in the original post. If
"abbarition" replies, post that version. If not, you gave the process in an
earlier post and consider that enough. Thanks for jumping in.

Abbarition, consider this a request for the version of Access you are using.
If you provide this information, I'm sure that Jeff will honor you with some
code.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
J

Jeff Conrad

Master,

OK, sounds good.
I just finished some extra little "touch-up" work on it.
Both versions seem to be working just fine.

'Abbarition' (or anyone else) I will need to know
which Access version you are using. It does make
a difference so please provide your current Access
version and I will post the module code.

Bueller....Bueller....Bueller....
<g>
 
T

tina

hi Jeff. i don't know if the original post-er is stilling following this
thread, but i'd be grateful to see your code for A2000. tia, tina :)
 
J

Jeff Conrad

Your wish is my command Tina.

You will need two new standard modules.
1. First module: basListAllMacros

Copy/Paste this code:

'*************Code Start******************
Public Function funcGetMacroList() As Variant
On Error GoTo ErrorPoint

' Code by Access MVP M.L. "Sco" Scofield
' http://www.scobiz.com
' And by Jeff Conrad - Access Junkie
' Copyright © 2005 Conrad Systems Development
' It is not to be altered or distributed,
' except as part of an application.
'
' Code will produce a list of all macro group names and
' internal names formatted to match the syntax found in
' all code Event Procedure lists
'
' This code will work with Access versions 2000, 2002, and 2003
' You must also set a reference to the DAO object library
'
' You are free to use this code in any projects providing
' you agree to the following two conditions:
' 1. This copyright information remains intact
' 2. You admit you are an Access Junkie
' (Why else would you be looking at this?) :)

Dim dbs As DAO.Database
Dim intFileIn As Integer
Dim strRow As String
Dim intCount As Integer
Dim strMacroNames As String
Dim strTempFileName As String
Dim blShowHidden As Boolean
Dim blIsHidden As Boolean
Dim strName As String

' Are we supposed to show hidden objects?
blShowHidden = Application.GetOption("Show Hidden Objects")

' Return reference to current database.
Set dbs = CurrentDb()

' Create a temp file in Windows Temp directory
strTempFileName = GetTempFile()

' Set the loop for the number of macro object in database
For intCount = 0 To dbs.Containers("scripts").Documents.Count - 1

' Capture the name of this macro object
strName = dbs.Containers("Scripts").Documents(intCount).Name

' Determine if this macro has been set to hidden
If Application.GetHiddenAttribute(acMacro, strName) = True Then
blIsHidden = True
Else
blIsHidden = False
End If

' Now determine if this macro has been deleted AND whether we should
' hide it if it has been set to Hidden based on user's properties setting
If Not (Left(strName, 7) = "~TMPCLP") And (blIsHidden Imp blShowHidden) Then
' Everything looks good so we are OK to proceed
' Export this macro to a text file
SaveAsText acMacro, strName, strTempFileName

' Open the text file we made from the macro
intFileIn = FreeFile
Open strTempFileName For Input As intFileIn

' Capture the name of this current macro object and add to list
strMacroNames = strMacroNames & ";" & strName

' Loop through text file looking for all instances of "MacroName="
' Print the name of any internal macro names by stripping out
' the preceeding information and the end quotation mark.
' Add the name of the current macro object and a period before
' the name of each macro group
Do Until EOF(intFileIn)
Line Input #intFileIn, strRow
If InStr(strRow, "MacroName =") <> 0 Then
strRow = Mid(strRow, 17)
strRow = strName & "." & strRow
strRow = Left(strRow, Len(strRow) - 1)
strMacroNames = strMacroNames & ";" & strRow
End If
Loop

'Close text file
Close intFileIn

Else
' If we reach here it is because current macro has either been
' 1. Deleted
' 2. Set to hidden AND Hide Hidden Objects has been set to True
' So we skip over all the above code and move on to the next one
End If

' Start next macro
Next intCount

' Strip out leading semi colon to arrive at complete formatted list
funcGetMacroList = Mid(strMacroNames, 2)

ExitPoint:
' Cleanup Code
On Error Resume Next
Set dbs = Nothing
' Delete the temp file we created
Kill strTempFileName
Exit Function

ErrorPoint:
' Display error message if an unexpected error occurs
' Exit the procedure through our cleanup code
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function
'*************Code End******************


2. Second Module: basTempFileNameWinAPI

Copy/Paste this code:

'*************Code Start******************
' Code by Access MVP M.L. "Sco" Scofield
' http://www.scobiz.com
' And by Jeff Conrad - Access Junkie
' Copyright © 2005 Conrad Systems Development
' It is not to be altered or distributed,
' except as part of an application.
'
' Functions to determine location of Windows Temp directory
' and create a temporary file name
'
' You are free to use this code in any projects providing
' you agree to the following two conditions:
' 1. This copyright information remains intact
' 2. You admit you are an Access Junkie
' (Why else would you be looking at this?) :)

Private Declare Function GetTempFileName Lib "kernel32" Alias _
"GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias _
"GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Public Function GetTempDirectory() As String

Dim lngBufferLength As Long
Dim lngLength As Long
Dim strBuffer As String * 255

lngLength = GetTempPath(255, strBuffer)

GetTempDirectory = Left$(strBuffer, lngLength)

End Function

Public Function GetTempFile() As String

Dim strBuffer As String * 255
Dim lngReturn As Long

lngReturn = GetTempFileName(GetTempDirectory(), "~ut", 0, strBuffer)

GetTempFile = Left$(strBuffer, InStr(strBuffer, Chr$(0)) - 1)

End Function
'*************Code End******************

3. Set you combo box or list box Row Source Type to "Value List"

4. Many ways to call it, but here are examples with Form_Open:

Private Sub Form_Open(Cancel As Integer)
Me.cboMacroList.RowSource = funcGetMacroList
Me.lstMacroList.RowSource = funcGetMacroList
End Sub

Have fun!
 
T

tina

you da man! :)


Jeff Conrad said:
Your wish is my command Tina.

You will need two new standard modules.
1. First module: basListAllMacros

Copy/Paste this code:

'*************Code Start******************
Public Function funcGetMacroList() As Variant
On Error GoTo ErrorPoint

' Code by Access MVP M.L. "Sco" Scofield
' http://www.scobiz.com
' And by Jeff Conrad - Access Junkie
' Copyright © 2005 Conrad Systems Development
' It is not to be altered or distributed,
' except as part of an application.
'
' Code will produce a list of all macro group names and
' internal names formatted to match the syntax found in
' all code Event Procedure lists
'
' This code will work with Access versions 2000, 2002, and 2003
' You must also set a reference to the DAO object library
'
' You are free to use this code in any projects providing
' you agree to the following two conditions:
' 1. This copyright information remains intact
' 2. You admit you are an Access Junkie
' (Why else would you be looking at this?) :)

Dim dbs As DAO.Database
Dim intFileIn As Integer
Dim strRow As String
Dim intCount As Integer
Dim strMacroNames As String
Dim strTempFileName As String
Dim blShowHidden As Boolean
Dim blIsHidden As Boolean
Dim strName As String

' Are we supposed to show hidden objects?
blShowHidden = Application.GetOption("Show Hidden Objects")

' Return reference to current database.
Set dbs = CurrentDb()

' Create a temp file in Windows Temp directory
strTempFileName = GetTempFile()

' Set the loop for the number of macro object in database
For intCount = 0 To dbs.Containers("scripts").Documents.Count - 1

' Capture the name of this macro object
strName = dbs.Containers("Scripts").Documents(intCount).Name

' Determine if this macro has been set to hidden
If Application.GetHiddenAttribute(acMacro, strName) = True Then
blIsHidden = True
Else
blIsHidden = False
End If

' Now determine if this macro has been deleted AND whether we should
' hide it if it has been set to Hidden based on user's properties setting
If Not (Left(strName, 7) = "~TMPCLP") And (blIsHidden Imp blShowHidden) Then
' Everything looks good so we are OK to proceed
' Export this macro to a text file
SaveAsText acMacro, strName, strTempFileName

' Open the text file we made from the macro
intFileIn = FreeFile
Open strTempFileName For Input As intFileIn

' Capture the name of this current macro object and add to list
strMacroNames = strMacroNames & ";" & strName

' Loop through text file looking for all instances of "MacroName="
' Print the name of any internal macro names by stripping out
' the preceeding information and the end quotation mark.
' Add the name of the current macro object and a period before
' the name of each macro group
Do Until EOF(intFileIn)
Line Input #intFileIn, strRow
If InStr(strRow, "MacroName =") <> 0 Then
strRow = Mid(strRow, 17)
strRow = strName & "." & strRow
strRow = Left(strRow, Len(strRow) - 1)
strMacroNames = strMacroNames & ";" & strRow
End If
Loop

'Close text file
Close intFileIn

Else
' If we reach here it is because current macro has either been
' 1. Deleted
' 2. Set to hidden AND Hide Hidden Objects has been set to True
' So we skip over all the above code and move on to the next one
End If

' Start next macro
Next intCount

' Strip out leading semi colon to arrive at complete formatted list
funcGetMacroList = Mid(strMacroNames, 2)

ExitPoint:
' Cleanup Code
On Error Resume Next
Set dbs = Nothing
' Delete the temp file we created
Kill strTempFileName
Exit Function

ErrorPoint:
' Display error message if an unexpected error occurs
' Exit the procedure through our cleanup code
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function
'*************Code End******************


2. Second Module: basTempFileNameWinAPI

Copy/Paste this code:

'*************Code Start******************
' Code by Access MVP M.L. "Sco" Scofield
' http://www.scobiz.com
' And by Jeff Conrad - Access Junkie
' Copyright © 2005 Conrad Systems Development
' It is not to be altered or distributed,
' except as part of an application.
'
' Functions to determine location of Windows Temp directory
' and create a temporary file name
'
' You are free to use this code in any projects providing
' you agree to the following two conditions:
' 1. This copyright information remains intact
' 2. You admit you are an Access Junkie
' (Why else would you be looking at this?) :)

Private Declare Function GetTempFileName Lib "kernel32" Alias _
"GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias _
"GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Public Function GetTempDirectory() As String

Dim lngBufferLength As Long
Dim lngLength As Long
Dim strBuffer As String * 255

lngLength = GetTempPath(255, strBuffer)

GetTempDirectory = Left$(strBuffer, lngLength)

End Function

Public Function GetTempFile() As String

Dim strBuffer As String * 255
Dim lngReturn As Long

lngReturn = GetTempFileName(GetTempDirectory(), "~ut", 0, strBuffer)

GetTempFile = Left$(strBuffer, InStr(strBuffer, Chr$(0)) - 1)

End Function
'*************Code End******************

3. Set you combo box or list box Row Source Type to "Value List"

4. Many ways to call it, but here are examples with Form_Open:

Private Sub Form_Open(Cancel As Integer)
Me.cboMacroList.RowSource = funcGetMacroList
Me.lstMacroList.RowSource = funcGetMacroList
End Sub

Have fun!
 
A

abbarition

A very belated THANK YOU to everyone who posted the
reply. I apologize for not posting the access version
(which was 2000 by the way, so I have the answer I
needed).

Thanks again!!!
 
J

Jeff Conrad

A very belated THANK YOU to everyone who posted the
reply. I apologize for not posting the access version
(which was 2000 by the way, so I have the answer I
needed).

Thanks again!!!

You're very welcome, glad I could help!
--
Jeff Conrad
Access Junkie
Bend, Oregon


I am adding modules into an existing database that is
maintained by someone who doesn't know (and has no
interest in knowing) VB. I am setting up a new form that
will allow them to easily add additional items and it
will run my code based off the values in the form's
RecordSource (a table).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top