Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to add a code module to Excel from Access via automation.
I've looked at these 2 sites for help: http://www.j-walk.com/ss/excel/tips/tip96.htm http://www.cpearson.com/excel/vbe.htm For starters, I'm trying to simply add a module to an Excel workbook from a standard Excel module. The code below returns this: This workbook has 6 modules. Error Number 440: Method 'Add' of object '_VBComponents' failed Is there something wrong with the way I'm instantiating newmod? Any guidance would be appreciated. Thanks in advance. Public Function AddModuleToExcel() On Error GoTo HandleErr Dim intCt As Integer Dim vbp As Object Dim newmod As Object If Val(Application.Version) = 10 Then Set vbp = ActiveWorkbook.VBProject If Err.Number < 0 Then MsgBox "Your security settings do not allow this procedure to run." _ & vbCrLf & vbCrLf & "To change your security setting:" _ & vbCrLf & vbCrLf & " 1. Select Tools - Macro - Security." & vbCrLf _ & " 2. Click the 'Trusted Sources' tab" & vbCrLf _ & " 3. Place a checkmark next to 'Trust access to Visual Basic Project.'", _ vbCritical Exit Function Else intCt = vbp.VBComponents.Count Debug.Print "This workbook has " & intCt & " modules." Set newmod = vbp.VBComponents.Add(vbext_ct_StdModule) newmod.Name = "MyNewModule" intCt = vbp.VBComponents.Count Debug.Print "This workbook has " & vbpCt & " modules." End If End If Exit_He Exit Function HandleErr: Debug.Print "Error Number " & Err.Number & ": "; Err.Description End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
How to programmatically determine which rows are outlined using Excel VBA code | Excel Programming | |||
Excel VBA - How do I programmatically change source code in another file? | Excel Programming | |||
programmatically open VBE and go to a specified procedure in target module? | Excel Programming | |||
Add reference programmatically before a module compiles | Excel Programming |