PDA

View Full Version : Prining from VBA not coming out in the correct size, please help me



leemcder
02-26-2018, 02:11 AM
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

werafa
02-26-2018, 09:22 PM
my first guess is that the used range and print range are different.

try using the immediate window to select the used range (activesheet.usedrange.select) and see what you get