cbjamel
08-16-2010, 03:51 PM
:banghead:Here is my problem. If I open Excel and type the code in the vb won't run. If I open VBA and click run it will run. What am I doing wrong??
Thanks,
Shane
excel 2003
Here is the code.
Sub Send()
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("G*** Order Form")
If (ws.Cells(20, 12).Value = "c*******") Then
With ws.Buttons.Add(475, 520, 40, 15)
.Caption = "Send"
.OnAction = "Mail_workbook_1"
End With
Else
ws.Cells(20, 12).Value = " "
End If
Set ws = Nothing
End Sub
Sub Mail_workbook_1()
Dim wb As Workbook
Dim I As Long
Set wb = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
For I = 1 To 3
wb.SendMail "c*****@msn.com", _
"G*** Order"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
End Sub
Thanks,
Shane
excel 2003
Here is the code.
Sub Send()
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("G*** Order Form")
If (ws.Cells(20, 12).Value = "c*******") Then
With ws.Buttons.Add(475, 520, 40, 15)
.Caption = "Send"
.OnAction = "Mail_workbook_1"
End With
Else
ws.Cells(20, 12).Value = " "
End If
Set ws = Nothing
End Sub
Sub Mail_workbook_1()
Dim wb As Workbook
Dim I As Long
Set wb = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
For I = 1 To 3
wb.SendMail "c*****@msn.com", _
"G*** Order"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
End Sub