Autoprint worksheet

anthony 1224

New Member
Joined
Apr 28, 2015
Messages
12
Greetings Forum,
Win 8
Excel 2010

I am working with a simple workbook that contains a ledger worksheet and individual worksheets linked to the ledger. I am trying to find out how to create a macro that will automatically print and individual worksheet if a specific cell on the ledger is changed. For example if I enter an amount on ledger B2 which is the ledger entry spot for Customer 1 then I would like the worksheet named "Customer 1" to print.
Thank you for the opportunity to post my question.
Anthony
 
how could I force this code to print to a specific printer we have several that are used and one specifically for this ledger which is not typically the default.
Thanks
Anthony

Add the red bit to the existing line:
Rich (BB code):
Sheets(CStr(Target.Offset(0, -1))).PrintOut Activeprinter:= "Your printer name here"
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi Joe,
the print adjustment worked!
In the same workbook I have a macro button then when clicked creates a pdf and emails the file. I have pasted the code below. It works well I have 2 minor issues maybe you can spot..#1 when it creates the pdf file it uses the name of the active worksheet and I would prefer it concatenate the text in cell A and cell B is this possible?
Secondly when it creates the pdf I have it pointing to cell A237 which contains the month and year. I originally tried to set that cell as "today" function but it blows up the macro and it will only accept text. I was wondering if there is a better way to get the month and date correct?

Sub create_and_email_pdf()


Dim EmailSubject As String, EmailSignature As String
Dim CurrentMonth As String, DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult
Dim OutlookApp As Object, Outlookmail As Object
CurrentMonth = ""



EmailSubject = " Invoice Attached "
OpenPDFAfterCreating = False
AlwaysOverwritePDF = False
DisplayEmail = True
Email_To = ActiveSheet.Range("p2")
Email_CC = ""
Email_BCC = ""

' ******************************************************


With Application.FileDialog(msoFileDialogFolderPicker)

If .Show = True Then

DestFolder = .SelectedItems(1)

Else

MsgBox "You must specify a folder to save the PDF into." & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Must Specify Destination Folder"

Exit Sub

End If

End With


CurrentMonth = Mid(ActiveSheet.Range("a237").Value, InStr(1, ActiveSheet.Range("a237").Value, " ") + 1)


PDFFile = DestFolder & Application.PathSeparator & ActiveSheet.Name _
& "_" & CurrentMonth & ".pdf"

If Len(Dir(PDFFile)) > 0 Then

If AlwaysOverwritePDF = False Then

OverwritePDF = MsgBox(PDFFile & " already exists." & vbCrLf & vbCrLf & "Do you want to overwrite it?", vbYesNo + vbQuestion, "File Exists")

On Error Resume Next

If OverwritePDF = vbYes Then

Kill PDFFile

Else

MsgBox "OK then, if you don't overwrite the existing PDF, I can't continue." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Exiting Macro"

Exit Sub

End If

Else

On Error Resume Next
Kill PDFFile

End If

If Err.Number <> 0 Then

MsgBox "Unable to delete existing file. Please make sure the file is not open or write protected." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"

Exit Sub

End If

End If



Sheets("1001").ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=OpenPDFAfterCreating


Set OutlookApp = CreateObject("Outlook.Application")
Set Outlookmail = OutlookApp.CreateItem(0)


With Outlookmail

.Display
.To = Email_To
.CC = Email_CC
.BCC = Email_BCC
.Subject = EmailSubject & CurrentMonth
.Attachments.Add PDFFile

If DisplayEmail = False Then

.Send

End If

End With

End Sub
 
Upvote 0
Hi Joe,
the print adjustment worked!
In the same workbook I have a macro button then when clicked creates a pdf and emails the file. I have pasted the code below. It works well I have 2 minor issues maybe you can spot..#1 when it creates the pdf file it uses the name of the active worksheet and I would prefer it concatenate the text in cell A and cell B is this possible?
Secondly when it creates the pdf I have it pointing to cell A237 which contains the month and year. I originally tried to set that cell as "today" function but it blows up the macro and it will only accept text. I was wondering if there is a better way to get the month and date correct?
I think the sheet name is what's used when you export as pdf. Here's a simple way around that:
1. Copy the sheet (let's say it's sheet 1001 and you copy it after 1001) so you now have a copy of that sheet and it will be the active sheet immediately after the copy. You can then rename the activesheet using the concatenation of your two cells.
2. After you have exported the pdf you can delete the copied sheet.

As far as the date goes, if you just want the name of the current month you can use:

CurrentMonth = MonthName(Month(Date))

Date is the VBA equivalent of TODAY()
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,574
Members
449,173
Latest member
Kon123

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