Print and Save to specific folder indicated by cel in worksheet.

WERNER SLABBERT

Board Regular
Joined
Mar 3, 2009
Messages
104
Morning all you smart people...
i have a vba code that saves and prints a document to a folder. i would like to expand it somewhat to ref a cell and then save the doc to the right folder.
currently it just saves to one folder. i need it to look at 'B9' and the find the corresponding folder and if it does not exist create it. the save the doc with the data from two other cells. 'G11 & C11'
the data in "B9' changes to the user need from a drop down from " Quote , Invoice , Job Card & Statement ", G11 & C11 respectively are the customer name and document nr.

Code:
Sub PrintSave()On Error Resume Next 'In case it already exists
MkDir GetSpecialfolder(CSIDL_DESKTOP) & "\Quotes"


    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
    Dim Filename As String
    Dim Path As String
    Filename = Range("L1").Value
    Path = CreateObject("Wscript.Shell").specialfolders("Desktop")
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        Path & "\Quotes\" & Filename & ".Pdf", Quality:= _
        xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
End Sub
 
Code:
[COLOR=darkblue]Sub[/COLOR] SaveAsPDF()
    
    [COLOR=darkblue]Dim[/COLOR] strPath [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], strFileName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    strPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & Range("B9").Value & "\"
    [COLOR=darkblue]If[/COLOR] Dir(strPath, vbDirectory) = "" [COLOR=darkblue]Then[/COLOR] MkDir strPath
    
    strPath = strPath & Range("G11").Value & "\"
    [COLOR=darkblue]If[/COLOR] Dir(strPath, vbDirectory) = "" [COLOR=darkblue]Then[/COLOR] MkDir strPath
        
    strFileName = Range("G11").Value & Range("C11").Value
        
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                    Filename:=strPath & strFileName & ".pdf", _
                                    Quality:=xlQualityMinimum, _
                                    IncludeDocProperties:=True, _
                                    IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=[COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Thank you for your patience Alpha you are a MAMBA !:rofl:
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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