In 2007, need code to save as pdf not excel sheet

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
How can I change my existing code to save as pdf?

Here is the code:
Code:
Dim strPath As String, strPath2 As String, CurrPath As String
    
    Dim WB1 As Workbook
    Dim WB2 As Workbook
    
    Application.ScreenUpdating = False
    
    Set WB1 = ActiveWorkbook
    
    WB1.Save
    
    CurrPath = WB1.Path
    
    strfilename = Range("S16").Value & ".xlsm"
    
    strPath = "C:\Documents and Settings\Owner\My Documents\Completed Proposals\"
    
    strPath2 = "C:\Documents and Settings\Owner\My Documents\Surface Systems\"
    
    On Error Resume Next
   
    WB1.SaveAs Filename:=strPath & strfilename
    On Error GoTo 0
    Set WB2 = Workbooks.Open(Filename:=strPath2 & "Proposal for XL.xlsm")
    Select Case WB1.Sheets("FRONT").Range("C2").Value
        Case "MD"
            strfilename = "C:\Documents and Settings\Owner\Desktop\Mike Prop\" & strfilename
            
        Case "TD"
            strfilename = "C:\Documents and Settings\Owner\Desktop\Tom Prop\" & strfilename
        Case "JK"
            strfilename = "C:\Documents and Settings\Owner\Desktop\Jon Knorr\" & strfilename
        Case "CP"
            strfilename = "C:\Documents and Settings\Owner\Desktop\Chuck Prop\" & strfilename
        Case "DA"
            strfilename = "C:\Documents and Settings\Owner\Desktop\David Prop\" & strfilename         
    End Select
    WB1.SaveCopyAs Filename:=strfilename
    WB1.ActiveSheet.Shapes("Button 53").Visible = False
    ChDir CurrPath
    Application.ScreenUpdating = True
    WB1.Close
I think this is the line I need changed? Not sure what i need it to change to?
Code:
WB1.SaveCopyAs Filename:=strfilename

Any help is greatly appreciated!
Michael
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I searched over on MicroSoft and found this:

<snip..snip>

The 2007 Microsoft Office system introduces multiple changes to the way developers can work with Excel 2007. Specifically, Microsoft Office Excel 2007 has support for the Microsoft Save as PDF Add-in for the 2007 Office release program, which allows an Excel workbook to export and save to the PDF format and XPS format. This is very useful for building Office business applications in which the data input and analysis is dynamic, but the application output is static. For example, a mortgage calculator application may require input and analysis using Excel's core features, but the final workbook is a PDF or XPS document.

http://msdn.microsoft.com/en-us/library/bb407651.aspx
 
Upvote 0
Mine does it with:

Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strfilename, Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

Not sure if that is because of an acrobat plugin though this is a ghost build.
 
Upvote 0
Hammerhead,
I have the download added. I just need to find out how to execute it using code.
Blade Hunter,
I see the code. I guess, I just am not sure how/where to put the code.

Michael
 
Upvote 0
I tried that. the problem I am having is the "Case Select" I need something that has a .pdf extension not an .xls extention.

Other Ideas?
Michael
 
Upvote 0

Forum statistics

Threads
1,223,574
Messages
6,173,144
Members
452,501
Latest member
musallam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top