Vba for printing documents - not printing correct size

leemcder

New Member
Joined
Feb 26, 2018
Messages
42
Hi, I am using the script below to print files in a specific location from excel, but the sheets are not printing in A4, they're about half the size they should be, can anyone please spot why? if I print the documents manually they are fine, but priting from the VBA is causing an issue. Thank you

Sub PrintFiles()
Dim oFSO As Object
Dim lngLastRow As Long
Dim lngIndex As Long
Dim strFname As String
Dim xlSheet As Worksheet
Dim xlWB As Workbook
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set xlSheet = ActiveSheet
With xlSheet
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For lngIndex = 1 To lngLastRow
strFname = .Range("A" & lngIndex)
If oFSO.FileExists(strFname) Then
'If oFSO.FileExists("C:\Path" & strFname) Then
'If oFSO.FileExists("C:\Path" & strFname & ".xls") Then
Set xlWB = Workbooks.Open(strFname)
'Set xlWB = Workbooks.Open("C:\Path" & strFname)
'Set xlWB = Workbooks.Open("C:\Path" & strFname& ".xls")
xlWB.Sheets(1).UsedRange.PrintOut
xlWB.Close savechanges:=False
Else
.Range("A" & lngIndex).Interior.Color = &H80FFFF
End If
Next lngIndex
End With
lbl_Exit:
Set oFSO = Nothing
Set xlSheet = Nothing
Set xlWB = Nothing
Exit Sub
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If you record your actions for printing, that would be different from what you have coded
 
Upvote 0
If you record your actions for printing, that would be different from what you have coded

I have recorded my macro for printing, this is it, how do I get my VBA to replicate this? I have a spreadsheet with a list of file names, the VBA prints all of the documents without me having to open each document and print them. It works but the size is wrong

Sub Macro1()
'
' Macro1 Macro
' test
'
'
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,335
Messages
6,124,327
Members
449,155
Latest member
ravioli44

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