create PDF based on cell content

GMC111568

New Member
Joined
Oct 3, 2016
Messages
11
Hi,
I am trying to set up a macro so that when I run it, in loops through all the cells in a column that have a value, and creates a PDF (using the name / location from the adjacent column)

So, I have a spreadsheet that looks like this:

1 c:\temp\1.pdf
2 c:\temp\2.pdf
3 c:\temp\3.pdf

When I run the Macro, I want to create 3 PDF - 1 with "1" in it, 1 with "2" in it, and 1 with "3" in it. (this is a small piece of a much larger project).

Here's what I have compiled based on other scripts that I have that do work....unfortunately, this doesn't seem to. When I run it, I get a "Compile error: Invalid qualifier"

Sub Main()
Dim MyFile As String, DestFile As String
Dim lastrow As Long


With ActiveSheet

lastrow = .Cells(1, .Rows.Count).End(xlToDown).Row
For i = 1 To lastrow

MyFile = .Cells(i, 1).Value
DestFile = .Cells(i, 2).Value
MyFile.ExportAsFixedFormat Type:=xlTypePDF, Filename:=DestFile
Next i
End With
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this:
Code:
Public Sub Create_PDFs()

    Dim lastRow As Long, r As Long
    
    With ActiveSheet
        lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        For r = 1 To lastRow
            .Cells(r, 1).ExportAsFixedFormat Type:=xlTypePDF, Filename:=.Cells(r, 2).Value, Quality:=xlQualityStandard
        Next
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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