Delete Module

B

Bre-x

Hi,

I need to delete a module programmatically. Here is my function ( It is on
ms access),

Public Function lathe_V11(tcid As Double, tlid As Double, custid As String,
mach As Integer, prog As Integer)
'Dim string Variables
Dim thepath As String

'Dim Excel Object
Dim objXL As Object
Set objXL = CreateObject("Excel.Application")
thepath = mypath & mach & "\" & custid & "\" & mach & prog & ".xls"



With objXL.Application
.Visible = True
.Workbooks.Open thepath
.ActiveWindow.WindowState = xlMinimized
.VBComponents("Module1").Remove
'........
'....More code................
End With
End Function


Could anyone help me?

Thanks

Bre-x
 
C

Chip Pearson

The following will remove Module1.


With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With


See www.cpearson.com/Excel/VBE.aspx for much more information and
example code about programmatically working with the VBA editor and
it's objects.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
B

Bre-x

Thank you for you answer.

It doesnt work. Sorry, I dont understand your instructions.


Public Function lathe_V11(tcid As Double, tlid As Double, custid As String,
mach As Integer, prog As Integer)
'Dim string Variables
Dim thepath As String

'Dim Excel Object
Dim objXL As Object
Set objXL = CreateObject("Excel.Application")
thepath = mypath & mach & "\" & custid & "\" & mach & prog & ".xls"


With objXL.Application
.Visible = True
.Workbooks.Open thepath
.ActiveWindow.WindowState = xlMinimized
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With

End With
End Function
 
B

Bre-x

Thank you. It works very well!!!


Peter T said:
add -
Dim objWB as Object

change -
to
set objWB = .Workbooks.Open(thepath)

and change -
to
With objWB .VBProject.VBComponents

Regards,
Peter T
 

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

Similar Threads

Talking to Excel 16
Run Time Error 1004 2
Sort and align 2 ranges 1
Getting values from Excel worksheet 4
delete modules 1
Array error in subtotal method 5
NumberFormat = "@" syntax 1
autorun macro from access 0

Top