VBA to convert pdf

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
165
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi Excel Experts.
I want to save excel sheet as pdf, file name is as per cell C15, location -desktop.
Thank you
 
When I have some time, I'll look into changing it to filtering on Sheet Names.
If you keep the "Data" & "Centre" Sheets as the two leftmost Sheets. If that will not be the case, macro needs to be changed.
Code:
Sub With_Three_Loops()
Dim myDir As String
Dim c As Range
Dim i As Long, j As Long
myDir = "C:\Abduls_PDF_Files\"    '<---- Change as required
For i = 3 To ThisWorkbook.Worksheets.Count
    Sheets(i).UsedRange.Offset(18).ClearContents
Next i
With Sheets("Data")
    For Each c In .Range("F2:F" & .Cells(.Rows.Count, 6).End(xlUp).Row)
        If Not Sheets(c.Value) Is Nothing Then
            With Sheets(c.Value)
                .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Resize(, 4).Value = c.Offset(, -4).Resize(, 4).Value
            End With
        End If
    Next c
End With
    For j = 3 To ThisWorkbook.Worksheets.Count
        With Sheets(j)
            If Len(.Cells(15, 3)) > 0 Then
                .PageSetup.PrintArea = .Range("A1:E" & .Cells(.Rows.Count, 5).End(xlUp).Row).Address
                .ExportAsFixedFormat 0, myDir & .Cells(15, 3).Value & ".pdf"
            End If
        End With
    Next j
End Sub
 
Upvote 0
Solution

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
When I have some time, I'll look into changing it to filtering on Sheet Names.
If you keep the "Data" & "Centre" Sheets as the two leftmost Sheets. If that will not be the case, macro needs to be changed.
It works perfect. Thanks once again.
 
Upvote 0
When I have some time, I'll look into changing it to filtering on Sheet Names.
If you keep the "Data" & "Centre" Sheets as the two leftmost Sheets. If that will not be the case, macro needs to be changed.
sorry, forget to say, add Sl. No. to every sheet up to used column B cell before covert pdf. please add one more code to get Sl. No. to every sheet
 
Upvote 0
Change this
Code:
If Not Sheets(c.Value) Is Nothing Then
            With Sheets(c.Value)
                .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Resize(, 4).Value = c.Offset(, -4).Resize(, 4).Value
            End With
        End If

to this
Code:
If Not Sheets(c.Value) Is Nothing Then
            With Sheets(c.Value)
                With .Cells(.Rows.Count, 2).End(xlUp).Offset(1)
                    .Resize(, 4).Value = c.Offset(, -4).Resize(, 4).Value
                    .Offset(, -1).Value = .Row - 18
                End With
            End With
        End If

Read the last line in Post #7 again.
 
Upvote 0
Change this
Code:
If Not Sheets(c.Value) Is Nothing Then
            With Sheets(c.Value)
                .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Resize(, 4).Value = c.Offset(, -4).Resize(, 4).Value
            End With
        End If

to this
Code:
If Not Sheets(c.Value) Is Nothing Then
            With Sheets(c.Value)
                With .Cells(.Rows.Count, 2).End(xlUp).Offset(1)
                    .Resize(, 4).Value = c.Offset(, -4).Resize(, 4).Value
                    .Offset(, -1).Value = .Row - 18
                End With
            End With
        End If

Read the last line in Post #7 again.
Thanks once again. I appreciate your patience.
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,331
Members
449,098
Latest member
thnirmitha

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