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
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