Excel helpings please

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
Don Carlos
Posts: 17515
Joined: Thu Jan 01, 1970 12:00 am

Excel helpings please

Post by Don Carlos »

Gentlemen, I have an excel issue I have no idea how to fix!

Trying to get a button on the bottom of a sheet that opens up an email, titles it and get the sheet ready to send. I got some code from a demo sheet that works perfectly but when I load it into my sheet, it comes up with "Cannot run the macro "xxxx" The macro may not be available on this sheet or macros may be disabled"

Both of those things are untrue. I am using Excl 2007 and the code is below

Code: Select all

Option Explicit

Sub Mail_ActiveSheet()
'Working in 97-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim I As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    'Copy the sheet to a new workbook
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010
            'We exit the sub when your answer is NO in the security dialog that you only
            'see  when you copy a sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheet to values if you want
    '    With Destwb.Sheets(1).UsedRange
    '        .Cells.Copy
    '        .Cells.PasteSpecial xlPasteValues
    '        .Cells(1).Select
    '    End With
    '    Application.CutCopyMode = False

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("c:\windows\addin") & "\"
    TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            .SendMail "", _
                      "Call a Coach"
            If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
How the hell do I get this working as it has baffled me? I was thinking it might be down to the temp file creation but then I have no clue what is really happening...ideas please peeps?

Cheers,

DC x
Deathshroud
Posts: 2103
Joined: Tue Feb 22, 2005 6:22 pm

Re: Excel helpings please

Post by Deathshroud »

Have you tried adding a button to the sheet, and assigning the macro to the button? Also, what format is the sheet you are working with? Does it differ from the demo sheet where you found the macro?
Don Carlos
Posts: 17515
Joined: Thu Jan 01, 1970 12:00 am

Re: Excel helpings please

Post by Don Carlos »

Yeah the macro is assigned to the button
The only difference is the original sheet is 2003 and mine is 2007
User avatar
seremtan
Posts: 36023
Joined: Wed Nov 19, 2003 8:00 am

Re: Excel helpings please

Post by seremtan »

jesus. i really need to advance my excel skillz. i can manage pivot tables and that's about it
User avatar
plained
Posts: 16366
Joined: Thu Jun 13, 2002 7:00 am

Re: Excel helpings please

Post by plained »

seremtan wrote:jesus. i really need to advance my excel skillz. i can manage pivot tables and that's about it

Yes me too I have'nt any idea what the fuck you guys are talking about!
it is about time!
Turbanator
Posts: 883
Joined: Wed Jun 08, 1983 7:00 am

Re: Excel helpings please

Post by Turbanator »

Save as XLSM. Skype / FB / Call me if you can't get it to work :)
Tsakali
Posts: 7175
Joined: Thu Mar 02, 2000 8:00 am

Re: Excel helpings please

Post by Tsakali »

lol pseudo coding noobs
mjrpes
Posts: 4980
Joined: Tue Nov 28, 2000 8:00 am

Re: Excel helpings please

Post by mjrpes »

Upload the spreadsheet and give us a link.
User avatar
Transient
Posts: 11357
Joined: Fri Feb 09, 2001 8:00 am

Re: Excel helpings please

Post by Transient »

Turbanator wrote:Save as XLSM. Skype / FB / Call me if you can't get it to work :)
Lurk much?
[quote="YourGrandpa"]I'm satisfied with voicing my opinion and moving on.[/quote]
Don Carlos
Posts: 17515
Joined: Thu Jan 01, 1970 12:00 am

Re: Excel helpings please

Post by Don Carlos »

Turbanator wrote:Save as XLSM. Skype / FB / Call me if you can't get it to work :)
Done already - still comes up with the same problem :(
User avatar
Eraser
Posts: 19183
Joined: Fri Dec 01, 2000 8:00 am

Re: Excel helpings please

Post by Eraser »

Visual Basic.... *shudder*
Don Carlos
Posts: 17515
Joined: Thu Jan 01, 1970 12:00 am

Re: Excel helpings please

Post by Don Carlos »

OK - Got the email springing up sorted. How do I auto fill the email address and make it send?
Don Carlos
Posts: 17515
Joined: Thu Jan 01, 1970 12:00 am

Re: Excel helpings please

Post by Don Carlos »

Code: Select all

Sub Email_Send()
' Email_Send Macro
    With ActiveWorkbook
.SendMail Recipients:="XXXX@XXXXX", _
Subject:="Call a Coach Appointment"
.Close SaveChanges:=False
End With
End Sub
BOOM!!!! >:D
Post Reply