Delete a module

P

Pete

I am tring to delete a module from excel using VBA. I have figured out how to
do this within the body of the Macro, but my problem comes in when I want to
link this to a macro that also saves the file to a directory on my computor
and also sends the workbook out as an attachment to a list of users.

This is what I got so far:

Sub Sendout()

'Saveas
Dim VBComp As Object

Dim FName As Variant
FName = Application.GetSaveAsFilename( _
filefilter:="Excel files (*.xls),*.xls")
If FName = False Then
' user clicked cancel
Else
ThisWorkbook.Saveas Filename:=FName
End If

'Rank
Range("A3:S32").Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select

ActiveWorkbook.Save

'Mailworkbook
Dim MyArr As Variant
MyArr = Sheets("Championship").Range("EmailNames")
ActiveWorkbook.SendMail MyArr, "Curtour Results"

Set VBComp = ThisWorkbook.VBProject.vbcomponents("Module1")
ThisWorkbook.VBProject.vbcomponents.Remove VBComp

ActiveWorkbook.Save

'DeleteMOD
Dim MyArr As Variant
MyArr = Sheets("Championship").Range("EmailNames")
ActiveWorkbook.SendMail MyArr, "Curtour Results"
End Sub

Any suggestions?
 

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