I am trying to write a very simple VB.net app which would open an excel file and save it as excel.
The environment I am working on is as follows:
Right! Thank you to all that tried to help. By reading your responses I kept trying till I figured out the issue.
It appears that ExportAsFixedFormat doesn't like Excel sheets with formulas in. To work around this issue, I just created a new blank worksheet and copied and pasted (values only) the content from my main sheet into it. This seems to work perfectly. I then automated this in my code as follows:
Dim xlworksheet_static As Excel.Worksheet = xlWorkBook.Worksheets(2)
xlWorkSheet.Range("A1", "H35").Copy()
xlworksheet_static.Activate()
xlworksheet_static.Range("A1", "H35").Select()
xlworksheet_static.PasteSpecial(Excel.XlPasteType.xlPasteValuesAndNumberFormats)
xlworksheet_static.ExportAsFixedFormat(Type:=Excel.XlFixedFormatType.xlTypePDF, Filename:=
"d:\test\test.pdf", Quality:=Excel.XlFixedFormatQuality.xlQualityStandard _
, IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=
False)
Probably not the most straight forward way but I couldn't get it to work otherwise!
Save it as .PDF like that:
xlWorkSheet.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, "d:\test\test.pdf")