Printing to file without being prompted and automatially set

me12345

New Member
Joined
Sep 14, 2006
Messages
12
I am a beginner in writing macros and will greatly appreciate assistance in the following:

I am Printing To File and have the name of the file to be printed contained in the Active Sheet at cell B47 in text format, every time I print, I am prompted to enter the file name, how do I set it to automatically apply
the name contained in cell B47

I also print different areas of the Active Sheet when calling the print Sub.
How do I place the Range to be printed which is specified by the content of cell B48 in text format and located in the Active Sheet, and place it into the ActiveSheet.PageSetup.PrintArea =
(i.e. Cell B48 contains A10:Y80 in text format I could also place into B48 the text $A$10:$Y$80)

Thanks in advane to anyone who could assist.

Sub PrintSA()
'
ActiveSheet.PageSetup.PrintArea = "$A$10:$Y$80"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I use the standard PrintToFile command since my default printer is a virtual PDF printer from www.go2pdf.com and I assumed that it will "take it" from the printer port

I will greatly appreciate any help with this.
 
Upvote 0
Take a look at the Printout method subject in VBA help.

It lists all the parameters that it works with, one of which is PrToFileName.

By the way are you trying to create pdf files?

If you are I'm not sure using print to file will work.
 
Upvote 0
Since I am trying to create PDF files, is there a command other then the PrintOut command I should be using?
 
Upvote 0
I tried this too, but it still prompts for a file name

Cell B49 on the active sheet named Mail contains the file name.

Sub GENERATEpdf()
Sheets("Mail").Select
Application.ActivePrinter = "Virtual PDF Printer on Ne01:"
ActiveWindow.SelectedSheets.PrintOut PrintToFile:=True, PrToFileName:=Worksheets("Mail").Range("B49").Value
End Sub
 
Upvote 0
I tried this too, but it still prompts for a file name

Cell B49 on the active sheet named Mail contains the file name.

Sub GENERATEpdf()
Sheets("Mail").Select
Application.ActivePrinter = "Virtual PDF Printer on Ne01:"
ActiveWindow.SelectedSheets.PrintOut PrintToFile:=True, PrToFileName:=Worksheets("Mail").Range("B49").Value
End Sub

Haven't tried this, but have you tried using the range as text instead of value?

Perry
 
Upvote 0
I tried using the Range as a .Text instead of .Value but it still prompted me for a file name.

Thanks to all for your suggestions, Please let me know of any potential solution.
 
Upvote 0
I tried using the Range as a .Text instead of .Value but it still prompted me for a file name.

Thanks to all for your suggestions, Please let me know of any potential solution.

What is the format of the cell? Is it using the full filename including the path?

Perry
 
Upvote 0
Cell B49 contains the full filename (minus the .PDF extension which is added by the Virtual PDF Printer) and it also includs the path.

I tried formating cell B49 as Text and as General and used the Range as .Text and .Value with no luck

I also tried recording a macro and using the following copy and paste procedure which did not help either: For copy I placed the cursor on cell B49 and pressed F2 then SHIFT + HOME then CTRL C and when prompted to enter a file name in the Save As table I placed it with CTRL + V

The code generated did not work either when I run it !!!

Thanks again
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,273
Members
448,559
Latest member
MrPJ_Harper

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