Link to home
Create AccountLog in
Avatar of jay_waugh
jay_waughFlag for United Kingdom of Great Britain and Northern Ireland

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.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.
Avatar of crystal (strive4peace)
crystal (strive4peace)

to solve the trust issue:

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
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.
ASKER CERTIFIED SOLUTION
Avatar of jay_waugh
jay_waugh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jay_waugh

ASKER

Was a simple case of removing the brackets to get the code to work.

ThisWorkbook.SaveAs Pathfilename, xlExcel12
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Good training tips
thanks, Jay, and you're welcome ~