troubleshooting Question

SaveAs Vba Excel 2010

Avatar of jay_waugh
jay_waughFlag for United Kingdom of Great Britain and Northern Ireland asked on
Visual Basic ClassicMicrosoft ExcelVBA
7 Comments2 Solutions222 ViewsLast Modified:
Experts

I have a excel 2010 .xlsm workbook that I have a button on to "export" data.

I am doing this by using the

ThisWorkbook.SaveCopyAs (filename)

Command and then removing the Sheets that are not required.

The file saves ok but then when I try and open the export, when either xls or xlsx or csv I get an error saying that the file is "in a different format than the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file.

I. was going to remove all macros code from ThisWorkbook to get around this but am struggling to do that too as I get a "Programmatic access to Visual Basic Project is not trusted"

Sub removecode()
ThisWorkbook.VBProject.VbComponents("ThisWorkbook").CodeModule.DeleteLines 1,ThisWorkbook.VBProject.VbComponents("ThisWorkbook").CodeModule.CountofLines
End sub

Can someone help me with the logic or the code.

Many thanks.
ASKER CERTIFIED SOLUTION
jay_waugh

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros