3

Hej, I am new in coding. I am trying my best but I am stuck. I have searched internet and stackoverflow but haven't find answer. I am writing code in Catia V5 VBA and I want to export excel to pdf. Excel has some pictures in color and I want that pdf is also in color. But I always end up with pdf in Black & white. This is my basic code:

Sub CATMain()
Set xlApp = CreateObject("Excel.Application")
Set mydoc = xlApp.Workbooks.Open("D:\Excel_1.xls")
Set mySheet = mydoc.Sheets.Item(1)

mySheet.ExportAsFixedFormat Type:=xlTypePDF, _
    fileName:="D:\Excel_1.pdf", _
    Quality:=xlQualityStandard, _
End Sub

I have looked for other parameters of "ExportAsFixedFormat" method, but there isn't any about color.

In despair I have also tried:

xlApp.ActiveWorkbook.SaveAs "D:\Excel_1.pdf"

But I get error saying: "Adobe Acribat could not open 'Excel_1.pdf' because it is either not a supported file type or because the file has been damaged"

Workbook.SaveAs method has "FileFormat" parameter but there isn't pdf in list of suportet file formats.

do you know what method should I use to get colored pdf?

thanks in advance

Community
  • 1
  • 1
CodeCatia
  • 127
  • 1
  • 9
  • It's strange because when I'm trying your code with mySheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="D:\Excel_1.pdf", Quality:=xlQualityStandard the pdf in output is colored. I presume when I read your question that you run your macro from Catia. Can you test your code from Excel (Excel > Visual Basic), and say to me if the pdf is still not colored ? – Putxe Sep 27 '17 at 09:32
  • Delete also the " , _" after xlQualityStandard if you are no other parameters after this. – Putxe Sep 27 '17 at 09:35
  • Thank you for your response. I have figured out what was problem, and it wasn't in code (beside unintentional ",_" part:)). I had to remove Page Setup/Sheet/Print check mark from Black and white. I was so focused on code that i didn't look to page set up options in excel. – CodeCatia Sep 27 '17 at 10:25

1 Answers1

2

If someone have same problem as I did, just add this code before exporting to pdf:

mySheet.PageSetup.BlackAndWhite = False

this will set sheet to print in color.

so, code will look like this:

Sub CATMain()

Set xlApp = CreateObject("Excel.Application")
Set mydoc = xlApp.Workbooks.Open("D:\Excel_1.xls")
Set mySheet = mydoc.Sheets.Item(1)

mySheet.PageSetup.BlackAndWhite = False

mySheet.ExportAsFixedFormat Type:=xlTypePDF, _
fileName:="D:\Excel_1.pdf", _
Quality:=xlQualityStandard

End Sub
CodeCatia
  • 127
  • 1
  • 9