print as pdf

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
667
Office Version
  1. 365
Platform
  1. Windows
hi,

it would be fanatastic if some kind and clever person could sort the following issue i have

print sheet 1 as a pdf (name will change each time )
and save to c:\sheets

hoping this is viable?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Something like this, which prints the active sheet. You need to determine what MyFileName is ahead of time.

Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\sheets\" & MyFileName & ".pdf"
 
Upvote 0
This should get you started, please feel free to test and post any question

Sorry the codes a little rushed

Regards
jiuk
Code:
Option Explicit
'/// Jack in the UK
'/// A little basic start

Const myFILE_TYPE As String = ".pdf"

Sub TEST_PDF_SAVE()

Dim mySAVE_Location As String
Dim myFILE_NAME As String

mySAVE_Location = "C:\Sheets"

'/// Error check the path is correct
If Right(mySAVE_Location, 1) <> "\" Then
        mySAVE_Location = mySAVE_Location & "\"
    End If
        
'/// jiuk - Check Dir Exists
    Dim myFOLDER As Object
    Application.ScreenUpdating = False
    Set myFOLDER = CreateObject("Scripting.FileSystemObject")
'// jiuk - Used to test
    If myFOLDER.FolderExists(mySAVE_Location) Then
      '  MsgBox "Exists"
    Else
        myFOLDER.CreateFolder (mySAVE_Location)
     '   MsgBox "ICreated."
    End If
'/// jiuk - Checck DIR exists or create DIR

myFILE_NAME = InputBox("Type File Name Here")

'// juik - Save the Worksheet as PDF - takes few seconds
ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=mySAVE_Location _
    & myFILE_NAME _
    & myFILE_TYPE

theEND:

Exit Sub
End Sub
 
Upvote 0
This might be worth changing, prints only sheet 2 without selection etc

Regards
jiuk
Code:
myFILE_NAME = InputBox("Type File Name Here")

'// juik - Save the Worksheet as PDF - takes few seconds
'ActiveSheet.ExportAsFixedFormat _
'    Type:=xlTypePDF, _
'    Filename:=mySAVE_Location _
'    & myFILE_NAME _
'    & myFILE_TYPE
    
ThisWorkbook.Sheets(2).ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=mySAVE_Location _
    & myFILE_NAME _
    & myFILE_TYPE

theEND:
 
Upvote 0
hello Jack in the UK,

Sorry for the delay getting back to you & thanks for sorting. yeah it works great. Very much appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

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