We help IT Professionals succeed at work.
Get Started

Print with a Specified File Name

Last Modified: 2012-05-11
Hi Experts,

I am using the following code to print the output to a pdf file using PDFXchange 4.0
In the printing Preferences "Show SaveAs" dialog is disabled / Unticked. Also the "Run Application after printing" option is unticked, so as to enable continuous Merging of documents after one another.
Everything is fine except that the file is saved with the same file as the Excel File and in the same directory. I wish to name the file based on value in Cell A1.

How the following code should be amended to achieve this ?

Sub PrintDV()
    Dim rng2 As Range, cel As Range
    Dim strFileName As String
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets(1)
    Set rng2 = ws.Range([g2], Cells(ActiveSheet.Rows.Count, "G").End(xlUp))
    MsgBox rng2.Address
    For Each cel In rng2
        ws.[c1] = cel
        If cel <> vbNullString Then ws.PrintOut
End Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 2 Answers and 36 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE