save excel 2007 worksheet as pdf in macro
Hi,
I think I have done a simular programming, try something like this.
You need pdf-add in.
Sub saveaspdft()
'
' Save as pdf Makro
'
Dim FilenameStr As String
If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _
& Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") < "" Then
FilenameStr = "C:\Mina dokument\" & _
ActiveSheet.Range("F23").Value & " " & Format(Now, "yyyy-mm-dd") &
".pdf"
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FilenameStr, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True,_
MsgBox " xxxx are now saved at " & FilenameStr
Else
MsgBox "PDF add-in are not installed"
End If
End Sub
As you can se I´m getting the filename from cell F3
God luck!
//
Mia
"Jania" skrev:
Hi,
I have recorded a macro in excel 2007 (with the Acrobat tab) to save an
excel sheet as a pdf. I can get the macro to make the pdf but it will not
save it. This is the code i have recorded:
Sub Macro1()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"R:\Actuarial Data\Form Filing Project\formfilingschvol2..pdf",
Quality:= _
xlQualityStandard, IncludeDocProperties:=True,
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
I changed it to this.
Sub pdf()
' creates a pdf of an excel worksheet
Dim stateint As String, shname As String, lob As String
stateint = Range("ca1").Value
shname = Range("ca4").Value
lob = Range("ca2").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"R:\Actuarial Data\" & lob & "\Filings\2008\" & stateint & "\" &
shname & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True,
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
When I run either one I get the error message: Run-time error '1004'.
Document not saved. The document may be open, or an error may have been
encountered when saving. If anyone has any suggestions as to how I can fix
this it would be appreciated. Thanks
|