First off, for the record, I am not a vba coder. I've taught myself enough over the years to be dangerous, but since I only need to script things once in a blue moon, have never had any official instruction.
That said, I'm trying to automate saving an Excel file as PDF using the Acrobat PDFMaker Office Com Add In. This is Excel 2007 with Acrobat 9.2 Standard installed. From Excel, I can click the office button and select save as - PDF with no troubles.
From what I've been researching online, the call for this should be:
But pretty much any variation I try on this results a run-time of either Object Required or Invalid Procedure Call or Argument. Am I missing something obvious in this? My main script is in a template that graphs data into a report. The script copies to a new workbook, modifies the charts to contain data only instead of links to the original, then saves. The main code is below. I've also tried this as a simple macro from a test file with the same error.
That said, I'm trying to automate saving an Excel file as PDF using the Acrobat PDFMaker Office Com Add In. This is Excel 2007 with Acrobat 9.2 Standard installed. From Excel, I can click the office button and select save as - PDF with no troubles.
From what I've been researching online, the call for this should be:
Code:
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Test\Test.pdf"
But pretty much any variation I try on this results a run-time of either Object Required or Invalid Procedure Call or Argument. Am I missing something obvious in this? My main script is in a template that graphs data into a report. The script copies to a new workbook, modifies the charts to contain data only instead of links to the original, then saves. The main code is below. I've also tried this as a simple macro from a test file with the same error.
Code:
Application.DisplayAlerts = False
Dim Fname As String
Dim FPath As String
Dim Sourcewb As Workbook
Dim Destwb As Workbook
FPath = "C:\Reports"
Fname = "Comparative Ratings - " & Sheets("Data").Range("D2").Text & " " & Sheets("Data").Range("C2").Text
Set Sourcewb = ActiveWorkbook
Sheets.Copy
Set Destwb = ActiveWorkbook
With Destwb
.Sheets("Report").Select
.Sheets("Report").Rows("2:4").Copy
.Sheets("Report").Rows("2:4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For Each Cht In Destwb.Sheets("Report").ChartObjects
Cht.Chart.ChartTitle.Characters.Text = Cht.Chart.ChartTitle.Characters.Text
For Each oSeries In Cht.Chart.SeriesCollection
With oSeries
.Name = .Name
.Values = .Values
.XValues = .XValues
End With
Next
Next
.Sheets("Data").Delete
.Sheets("Report").Range("A6").Select
.SaveAs Filename:=FPath & "\" & Fname, FileFormat:=56
.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FPath & "\" & Fname, OpenAfterPublish:= False
.Close
End With
'Turn alerts back on
Application.DisplayAlerts = True
End Sub