jay_waugh
asked on
SaveAs Vba Excel 2010
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.VbC omponents( "ThisWorkb ook").Code Module.Del eteLines 1,ThisWorkbook.VBProject.V bComponent s("ThisWor kbook").Co deModule.C ountofLine s
End sub
Can someone help me with the logic or the code.
Many thanks.
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.VbC
End sub
Can someone help me with the logic or the code.
Many thanks.
Navigate to File Tab, and then click Excel Options--> Trust Center -->Trust Center Settings --> Privacy Options.
Clear the Check Office documents that are from or link to suspicious Web sites check box.
and
Navigate to File Tab--> Options-->Trust Center --> Trust Center Settings --> Trusted Locations.
Click Add new location.
Click Browse to find the folder you wish to add as trusted location, select the folder, and then click OK.
Clear the Check Office documents that are from or link to suspicious Web sites check box.
and
Navigate to File Tab--> Options-->Trust Center --> Trust Center Settings --> Trusted Locations.
Click Add new location.
Click Browse to find the folder you wish to add as trusted location, select the folder, and then click OK.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Was a simple case of removing the brackets to get the code to work.
ThisWorkbook.SaveAs Pathfilename, xlExcel12
ThisWorkbook.SaveAs Pathfilename, xlExcel12
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Good training tips
thanks, Jay, and you're welcome ~
File > Options > Trust Center
click the Trust Center Settings command button
on left sidebar: Macro Settings
check --> Trust access to the VBA project object model