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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
Welcome to the Board!

Please post the code you have for the "print to file"
 

me12345

New Member
Joined
Sep 14, 2006
Messages
12
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
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.
 

me12345

New Member
Joined
Sep 14, 2006
Messages
12

ADVERTISEMENT

Since I am trying to create PDF files, is there a command other then the PrintOut command I should be using?
 

me12345

New Member
Joined
Sep 14, 2006
Messages
12
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
 

pfarmer

Well-known Member
Joined
Jul 6, 2005
Messages
550

ADVERTISEMENT

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
 

me12345

New Member
Joined
Sep 14, 2006
Messages
12
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.
 

pfarmer

Well-known Member
Joined
Jul 6, 2005
Messages
550
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
 

me12345

New Member
Joined
Sep 14, 2006
Messages
12
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
 

Forum statistics

Threads
1,141,098
Messages
5,704,319
Members
421,338
Latest member
Pepess

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
Top