VBA script needed

blurr1974

New Member
Joined
Feb 22, 2016
Messages
2
I'm trying to create a looped script that changes the value of one cell, saving it as a PDF after each change, until that cell equals the value of another cell.

As an added degree of difficulty, I then want to attach all the PDF files to an outgoing email.

To add a little more detail to my request, I am creating a template that will always be a # of # copies (ie: "file name 1 of 10.pdf") that loops until all are done. Once they are done, I'd like them all attached to an email. I really hope that makes sense, I'm still kind of new at all this...


Any help with this would be greatly appreciated.

Thanks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Ok, to see if we are on the right track this will loop through and create a new PDF while cell B1 is less than cell A1.
Each time it loops it names the PDF after whatever is incell B1.....is that the sort of thing you are after
Code:
Sub PDFActiveSheet()
Dim ws As Worksheet, strPath As String, myFile As Variant
Dim strFile As String
Do While Range("B1").Value < Range("A1").Value
strFile = Range("B1").Value & ".pdf"
strFile = ThisWorkbook.Path & "\" & strFile
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFile, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=true
With Range("B1")
.Value = .Value + 1
End With
Loop
End Sub
 
Upvote 0
I'll make a few minor tweaks to get it saving where I want, and in the file name format I'd like, but I think this should do the trick!

Thank you so much!
 
Upvote 0
OK, when you've tweaked post back with the emailing requirements...(y)
 
Upvote 0

Forum statistics

Threads
1,215,944
Messages
6,127,835
Members
449,411
Latest member
adunn_23

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