fix send attachement VBA code

Can any one edit the code below so I do not get the following errors

error 1 - This extension cannot be used with the selected file type. The the file extension in the file name text box or select a different file type by changing the Save as type.

I have changed the extension from .xlsm to xlsx - when I do this I get the following error

error 2
Method save as object  '_workbook' failed

I am trying to achieve the output outlined in the question link below.

http://www.experts-exchange.com/questions/28692112/save-and-send-VBA-code.html

Macro


Sub deletecolumns()
'
' deletecolumns Macro
'

'

    Columns("A:F").Delete Shift:=xlToLeft
    ActiveWindow.SmallScroll ToRight:=13
    Columns("P:Q").Delete Shift:=xlToLeft
    Columns("Q:Q").Delete Shift:=xlToLeft
    Columns("R:CX").Delete Shift:=xlToLeft
    Sheets("Database").Copy
    ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & "member database.xlsm"
    Res = InputBox("Enter E-mail")
    ActiveWorkbook.SendMail Recipients:=Res
End Sub
mikes6058Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
HI,

then try

 Sub deletecolumns()
 '
 ' deletecolumns Macro
 '

 '
     Set wkb = ActiveWorkbook
     Columns("A:F").Delete Shift:=xlToLeft
     ActiveWindow.SmallScroll ToRight:=13
     Columns("P:Q").Delete Shift:=xlToLeft
     Columns("Q:Q").Delete Shift:=xlToLeft
     Columns("R:CX").Delete Shift:=xlToLeft
     Sheets("Database").Copy
     ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & "member database", xlOpenXMLWorkbook
     Res = InputBox("Enter E-mail")
     ActiveWorkbook.SendMail Recipients:=Res
     wkb.Close False
 End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ProfessorJimJamCommented:
error 1  you are getting this error becuase you must have been saving a excel file that has codes in VBA module or worksheet or workbook object.   to get rid of this error, you need to delete the codes before trying to save file from xlsm to xlsx.

in regard to the other error.  

i believe Rognozo already provided solution to you on the referred link . code is

 Sub deletecolumns()
 '
 ' deletecolumns Macro
 '

 '
     Set wkb = ActiveWorkbook
     Columns("A:F").Delete Shift:=xlToLeft
     ActiveWindow.SmallScroll ToRight:=13
     Columns("P:Q").Delete Shift:=xlToLeft
     Columns("Q:Q").Delete Shift:=xlToLeft
     Columns("R:CX").Delete Shift:=xlToLeft
     Sheets("Database").Copy
     ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & "member database", xlOpenXMLWorkbook
     Res = InputBox("Enter E-mail")
     ActiveWorkbook.SendMail Recipients:=Res
     wkb.Close False
 End Sub

Open in new window

0
Rgonzo1971Commented:
HI,

if you do not want the message to confirm to save your file without macro

then use

 Sub deletecolumns()
 '

     Set wkb = ActiveWorkbook
     Columns("A:F").Delete Shift:=xlToLeft
     ActiveWindow.SmallScroll ToRight:=13
     Columns("P:Q").Delete Shift:=xlToLeft
     Columns("Q:Q").Delete Shift:=xlToLeft
     Columns("R:CX").Delete Shift:=xlToLeft
     Sheets("Database").Copy
     Application.DisplayAlerts = False
     ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & "member database", xlOpenXMLWorkbook
     Application.DisplayAlerts = True
     Res = InputBox("Enter E-mail")
     ActiveWorkbook.SendMail Recipients:=Res
     wkb.Close False
 End Sub

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

mikes6058Author Commented:
Using the last code you sent I am still getting the error 2
Method save as object  '_workbook' failed

Do I have to add a path (location) for the file to save to?

Mike
0
Rgonzo1971Commented:
Yes change at line 12

ActiveWorkbook.Path

with the path you want
0
mikes6058Author Commented:
Sorry what exactly do I have to replace with the path?

Mike
0
mikes6058Author Commented:
don't worry I've figured it out. Great work
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.