Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active December 19, 2015 12:19
Show Gist options
  • Save TLMcode/5954308 to your computer and use it in GitHub Desktop.
Save TLMcode/5954308 to your computer and use it in GitHub Desktop.
SaveXLValue().ahk strips everything but the value from an excel worksheet, leaves basic format intact.
Worksheet := A_ScriptDir "\Test.xls" ; << change this to your source worksheet
SaveXLValue(Worksheet, A_ScriptDir "\newfile.xls")
Return
SaveXLValue(_wrksht,_xls,_vis=0) ; << source worksheet, ouput worksheet, optional visible for debugging
{
xlObj:=ComObjCreate("Excel.Application"), xlObj.Visible:=_vis
xlObj.Workbooks.Open(_wrksht), xlObj.ActiveSheet.UsedRange.Select
SelVal:=xlObj.Selection.value
Loop % (2,EndRng:=[],erObj:=xlObj.Selection)
EndRng.Insert((i:=i!)?erObj.Rows.Count:erObj.Columns.Count)
FileDelete % _xls, (xlObj.Workbooks.Close), xlObj.Workbooks.Add
xlObj.Sheets(1).Range(xlObj.Cells(1,1), xlObj.Cells(EndRng[1],EndRng[2])).Select
(xlObj.Selection.value:=SelVal), (xlObj.ActiveWorkbook.SaveAs(_xls)), xlObj.Quit
}
ESC::ExitApp ; << Press escape to exit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment