Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2010, 01:11 AM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA to read VBA

I have inherited a large Access 2007 database from another programmer. It has many lines of VBA code. I need to write some VBA code in this database to scan the other programmer's VBA to look for certain constructs.

Can someone get me started writing this type of code? I am an experienced Access VBA programmer, but have never written code to read code.

Thanks
 
Old September 29th, 2010, 12:57 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

I find this tool useful:

Total Access Analyzer

It is possible to write VBA code to read through all the code in all modules a databases. Is that what you want to do?
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old September 29th, 2010, 12:59 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

also see:

How to Programmatically Create, Search, Replace, and Modify Code
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old October 6th, 2010, 04:20 PM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Something Similar From Excel VBA

I know this is about Access but what the heck? I did this to delete VBA modules from an Excel workbook a long time ago and it worked fine. Maybe it will point you in the general direction:

Function DeleteVBCode(wbDeliverable As Workbook) As Integer
'Deletes all VBA code from the workbook whose name is passed as a parameter.
'The following constants are as defined in Microsoft VBA help.
'Topic: Type Property (VBA Add-In Object Model).
'(Search on the word Type.)
'Use them to determine what type of VBA object a particular VBComponent is.
Const vbext_ct_StdModule As Long = 1 'Standard module
Const vbext_ct_ClassModule As Long = 2 'Class module
Const vbext_ct_MSForm As Long = 3 'Microsoft form
Const vbext_ct_ActiveXDesigner As Long = 11 'ActiveX Designer
Const vbext_ct_Document As Long = 100 'Document module

Dim n
Dim wb As Excel.Workbook
Dim objVbc As Object
Dim lnStLine As Long, lnDeclarationLines As Long

DeleteVBCode = Error 'Error condition

'Select workbook from which to delete VBA code.
For Each objVbc In wbDeliverable.VBProject.VBComponents
'Loop through the VBComponents and delete certain types.
'Debug.Print objVbc.Name, objVbc.Type
Select Case objVbc.Type
Case vbext_ct_StdModule, vbext_ct_ClassModule
'Delete the module.
wbDeliverable.VBProject.VBComponents.Remove objVbc
Case vbext_ct_Document
'This is code that goes with a worksheet or something similar.
'You can't remove this VBComponent, so just delete the individual
'lines of code.
lnDeclarationLines = objVbc.codemodule.CountOfDeclarationLines + 1
lnStLine = objVbc.codemodule.CountOfLines
If lnStLine < lnDeclarationLines Then
'The object contains no code. It's empty. Do nothing.
Else
'The object is not empty. Delete individual lines of code.
'You do it one line at a time.
'You use the Do Loop Until mode instead of a For Next loop
'because For Next won't work. The .DeleteLines doesn't always
'delete the entire line if the line is long and wraps to multiple
'screen line. Thus, if you have 100 lines of code and you
'remove 100 lines, you may actually have some lines left over,.
'fragments of the original 100.
Do
objVbc.codemodule.DeleteLines (1)
lnStLine = objVbc.codemodule.CountOfLines
Loop Until lnStLine = 0
End If
End Select
Next
Exit_DeleteVBCode:
DeleteVBCode = OK 'Results OK.
Set objVbc = Nothing
End Function
 
Old February 4th, 2015, 02:52 AM
Registered User
 
Join Date: Feb 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ffairchild View Post
I know this is about Access but what the heck? I did this to delete VBA modules from an Excel workbook a long time ago and it worked fine. Maybe it will point you in the general direction:

Function DeleteVBCode(wbDeliverable As Workbook) As Integer
'Deletes all VBA code from the workbook whose name is passed as a parameter.
'The following constants are as defined in Microsoft VBA help.
'Topic: Type Property (VBA Add-In Object Model).
'(Search on the word Type.)
'Use them to determine what type of VBA object a particular VBComponent is.
Const vbext_ct_StdModule As Long = 1 'Standard module
Const vbext_ct_ClassModule As Long = 2 'Class module
Const vbext_ct_MSForm As Long = 3 'Microsoft form
Const vbext_ct_ActiveXDesigner As Long = 11 'ActiveX Designer
Const vbext_ct_Document As Long = 100 'Document module

Dim n
Dim wb As Excel.Workbook
Dim objVbc As Object
Dim lnStLine As Long, lnDeclarationLines As Long

DeleteVBCode = Error 'Error condition

'Select workbook from which to delete VBA code.
For Each objVbc In wbDeliverable.VBProject.VBComponents
'Loop through the VBComponents and delete certain types.
'Debug.Print objVbc.Name, objVbc.Type
Select Case objVbc.Type
Case vbext_ct_StdModule, vbext_ct_ClassModule
'Delete the module.
wbDeliverable.VBProject.VBComponents.Remove objVbc
Case vbext_ct_Document
'This is code that goes with a worksheet or something similar.
'You can't remove this VBComponent, so just delete the individual
'lines of code.
lnDeclarationLines = objVbc.codemodule.CountOfDeclarationLines + 1
lnStLine = objVbc.codemodule.CountOfLines
If lnStLine < lnDeclarationLines Then
'The object contains no code. It's empty. Do nothing.
Else
'The object is not empty. Delete individual lines of code.
'You do it one line at a time.
'You use the Do Loop Until mode instead of a For Next loop
'because For Next won't work. The .DeleteLines doesn't always
'delete the entire line if the line is long and wraps to multiple
'screen line. Thus, if you have 100 lines of code and you
'remove 100 lines, you may actually have some lines left over,.
'fragments of the original 100.
Do
objVbc.codemodule.DeleteLines (1)
lnStLine = objVbc.codemodule.CountOfLines
Loop Until lnStLine = 0
End If
End Select
Next
Exit_DeleteVBCode:
DeleteVBCode = OK 'Results OK.
Set objVbc = Nothing
End Function
This code is not working.

Can you share the workbook or procedure how you used it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use VBA to Read/Write a Access Query Gino Liu Access VBA 2 January 7th, 2012 04:03 AM
VBA Code to read the structure & data of an excel alam1 Excel VBA 0 April 24th, 2007 11:39 PM
Read Excel Lines VBA gbvdh VB How-To 0 February 26th, 2007 08:44 AM
VBA Formatting cells with Html tags read from XML hemagiri Excel VBA 0 November 22nd, 2006 02:41 AM
Error when VBA tries to read from SQLDB atlcdp VB Databases Basics 1 December 28th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.