Question

Excel Macro to not save to Excel when creating PDFs

Asked by: flickimp1717

Hi

I have a workbook that is in excess of 25MB

The below Macro susccessfully runs through a loop of 151 codes, and creates 151 Excel files and then PDFs them...... and it works well..

Except the part when it saves as Excel....it takes forever....and that is due to the excel fiel size.

What I want is to modify the process.

Currently it does:

* First Loop
* Formalas calculate....
* Saves as New Filename in Excel
* Converts to PDF using the new filename
* Next Loop....thus next new filename....etc

I want to remove the step where it saves as an excel file, but i do want it to use the latest filename when it converts to PDF.

How?

Sub PDFer()
 
'Macro created by Imran Siddiq
 
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For I = 1 To 151
Sheets("Title").Select
Range("G10").Value = Range("E" & 1 + I).Value
 
Sheets(Array("Title", "EM", "EL", "DC", "OP_1ST", "OP_FU", "FIRST_TO_FOLLOWUP_RATIO", "CASSIUS_AE", "UHL_AE")).Select
Sheets("TITLE").Activate
Sheets(Array("Title", "EM", "EL", "DC", "OP_1ST", "OP_FU", "FIRST_TO_FOLLOWUP_RATIO", "CASSIUS_AE", "UHL_AE")).Copy
 
ThisFile = Range("G1").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
 
ActiveWorkbook.PrintOut copies:=1, ActivePrinter:= _
"doPDF v6:", Collate:=True
 
Dim sht As Worksheet
ActiveWorkbook.Close
 
Next I
 
Application.DisplayAlerts = True
Application.ScreenUpdating = True
 
MsgBox ("Job Done")
 
End Sub

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-03 at 06:07:43ID24542245
Tags

Excel

,

MAcro

,

PDF

,

Save

,

Automate

Topic

Microsoft Excel Spreadsheet Software

Participating Experts
1
Points
50
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Convert to .PDF macro
    I tried recording a macro to convert my Excel sheet to .pdf, but when I open VBA, and look through the module, it writes the name of the macro, but doesn't have any code. What's the macro to convert Excel to .PDF? This works: Application.DisplayAlerts = False Appli...
  2. Code to open and convert workbooks into PDF files.
    I tried creating a macro to automate conversion into PDF of 3 workbooks I have to send out every week, but of course this was all I got: Sub MakePDF() Workbooks.Open Filename:= _ "G:\..\MyWorkbook1.xls" ActiveWindow.Close Workbooks.Open Filename...
  3. Macro to merge PDFs in directory
    I have the following folder structure: Folder for PDF Merge Office A one.pdf two.pdf etc.pdf Office B one.pdf two.pdf etc.pdf Does anyone have a macro that will go into each of the "Office" folders and merge all the PDF's ...
  4. convert snp to pdf in macro
    Hi experts, I am trying to create a macro that outputs an SNP report file and then converts the SNP file to PDF. I can write the first but to output the SNP file but do not know how to automate the conversion to PDF. Can anybody help? Many thanks, Terry
  5. Macro to export to PDF
    I have an application which runs a report daily. Currently the results are e-mailed as an excel file, but now we are going to be sending the report to an outside company as well and we want to give them a PDF. I have acrobat installed on my computer. I am looking for a mac...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: flickimp1717Posted on 2009-07-03 at 09:35:48ID: 24773353

Hi Any help please?

 

by: CbrinePosted on 2009-07-03 at 10:02:32ID: 24773477

I did some research on this, and I don't believe that it is possible to change the name of the excel file without saving it.  Have you checked to see if your PDF converter allows you to change the default savename option?  Maybe to the sheet instead of the filename?  If so, that's an easy change in the code without saving anything.  The only other option is to somehow reduce the size of your file so that your save takes place in a reasonable time.  Try removing all formating prior to doing the save, this might help reduce the time invovled.

HTH
Cal

 

by: CbrinePosted on 2009-07-03 at 10:06:03ID: 24773497

Here's an easy way to remove formatting.

ActiveSheet.Cells.ClearFormats

                                              
1:

Select allOpen in new window

 

by: flickimp1717Posted on 2009-07-03 at 11:07:20ID: 24773733

Problem is I have tons of vlookups and i need them to stay intect for each of the 151 loops.

What does ActiveSheet.Cells.ClearFormats actually do?

 

by: CbrinePosted on 2009-07-03 at 11:26:22ID: 24773813

It just clears the formatting...colors....borders...fonts...bold..underline...etc....  These increase the size of the file, so if you eliminate them, the size decreases, which reduces the save time.

Since you have many vlookups, the recalc might be what is slowing your down as well. You might want to think about doing the following.

Copy pastespecial values.

Save as a temporary name that would fit your PDF naming needs.

HTH
Cal

activesheet.cells.clearformats
activesheet.cells.copy
activesheet.cells.pastespecial xlpastevalues
activeworkbook.saveas "Temp Name.xls"
                                              
1:
2:
3:
4:

Select allOpen in new window

 

by: flickimp1717Posted on 2009-07-03 at 11:26:49ID: 24773816

Okay.... lets expland on this

How do I get the macro to:

a) change the tab name to be the name present in CELL G1
b) then the filename is equal to the tab name
c) then save as PDF...without saving as XLS

 

by: CbrinePosted on 2009-07-03 at 11:27:51ID: 24773821

Just reading your message again, I would suggest you set this process up in it's own workbook.

Open workbook, remove formats, copypaste values, save under temp name. close workbook, iterate the loop, and so the same again.

 

by: CbrinePosted on 2009-07-03 at 11:29:34ID: 24773829

Was this comment helpful? Yes No flickimp1717: Okay.... lets expland on this

How do I get the macro to:

a) change the tab name to be the name present in CELL G1
b) then the filename is equal to the tab name
c) then save as PDF...without saving as XLS

The only problem is that step b) requires a save of the file.  The ONLY way to update the filename is to save the file.  My original suggestion was to check and see if the PDF software has an option that allows you to use the tab name instead of the filename.

 

by: flickimp1717Posted on 2009-07-03 at 11:46:58ID: 24773889

Ok...

At what point do I add :

Open workbook, remove formats, copypaste values, save under temp name. close workbook, iterate the loop, and so the same again.

to my original code?

Because...I dont want to lose the formuals in my master code...

 

by: flickimp1717Posted on 2009-07-03 at 11:47:36ID: 24773892

By the way using DoPDFv.6 which is free so cant alter the file thing

 

by: CbrinePosted on 2009-07-03 at 11:54:50ID: 24773928

OK,  Will need to understand a few more things in order to get down to coding this.

Looks like your code is cycling through the values in column E of the titles worksheet, and saving the sheets under this name, then converting to PDF via the printout function.

You array select a bunch of sheets, then you activate title, which would ungroup the sheets, then you copy them, but never paste them anywhere?  What exactly are you trying to accomplish with piece of code?

Sheets(Array("Title", "EM", "EL", "DC", "OP_1ST", "OP_FU", "FIRST_TO_FOLLOWUP_RATIO", "CASSIUS_AE", "UHL_AE")).Select
Sheets("TITLE").Activate
Sheets(Array("Title", "EM", "EL", "DC", "OP_1ST", "OP_FU", "FIRST_TO_FOLLOWUP_RATIO", "CASSIUS_AE", "UHL_AE")).Copy
 

                                              
1:
2:
3:
4:

Select allOpen in new window

 

by: flickimp1717Posted on 2009-07-03 at 12:03:18ID: 24773962

Hi

As you have said, thats what I am trying to do:
Looks like your code is cycling through the values in column E of the titles worksheet, and saving the sheets under this name, then converting to PDF via the printout function.

The aim is:
Start ar first value in column E, to determine main lookup for all the sheets.
Vlookups kick in and update all the sheets
I then want that to be saved as a pdf file.
then next loop in the E column

Maybe there was no need for me to have the copy bit in my code?

Is there a simple coe that woulg copy and paste values on all the sheets without writign a code for each one?

 

by: CbrinePosted on 2009-07-03 at 12:30:04ID: 24774065

Give these revisions a try.

HTH
Cal

Dim wb As Workbook, ws As Worksheet
Dim cell As Range
 
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
 
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Title")
ws.Cells.ClearFormats
 
For Each cell In ws.Range("E2", ws.Range("E65535").End(xlUp))
    ws.Range("G10").Value = cell
    wb.SaveAs Filename:=ws.Range("G1").Value
    wb.PrintOut copies:=1, ActivePrinter:="doPDF v6:", Collate:=True
Next cell
 
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
 
MsgBox ("Job Done")
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

 

by: CbrinePosted on 2009-07-03 at 12:34:25ID: 24774076

And now that I think about it a little more, removing your formats prior to printing to PDF will speed up the save, but will eliminate the formats that you need to produce the PDF, which makes no sense either.  You will need to remove the code that removes the formats.  Same problem occurs for my other suggestion, with copying and pasting values.  Since you cycle to the next value in E, you need the vlookups to refresh at that point.  I don't there is a whole lot we can do to speed this process up.  My suggested revisions will speed it up some, but it's still needs to recalculate all the formulas prior to the save, and you have to do the save to update the filename for the pdf conversion.

Cal

Dim wb As Workbook, ws As Worksheet
Dim cell As Range
 
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
 
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Title")
 
For Each cell In ws.Range("E2", ws.Range("E65535").End(xlUp))
    ws.Range("G10").Value = cell
    wb.SaveAs Filename:=ws.Range("G1").Value
    wb.PrintOut copies:=1, ActivePrinter:="doPDF v6:", Collate:=True
Next cell
 
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
 
MsgBox ("Job Done")

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: flickimp1717Posted on 2009-07-03 at 13:01:13ID: 24774161

Hi

Thanks for that, but the formulas are not refrrshing as they should.
ie:
The first file should say C82xx1 in the file name but instead gives a blank
Its almost as if the code isnt recalculating?

 

by: CbrinePosted on 2009-07-04 at 08:43:28ID: 24777170

I've set the recalculation to manual, which should prevent the calculation from occurring unless you press F9, but this is overridden by the save.  A forced recalculation will occur when the save occurs.  The will prevent any unintentional recalculations from occurring.  You will not see this on the screen, but your PDF should show the correct values.  If not, we may need to turn the calc's back on just prior to the save.

HTH
Cal

 

by: flickimp1717Posted on 2009-07-05 at 06:55:56ID: 24780023

Thanks

I changed the code to

For Each cell In ws.Range("E2", ws.Range("E152").End(xlUp))
    ws.Range("G10").Value = cell
    wb.SaveAs Filename:=ws.Range("G1").Value

but it stops after the first 2 files???? and doesnt do the whole 151?
why is that?

 

by: CbrinePosted on 2009-07-05 at 08:33:58ID: 24780285

If you have a specific range you want to act on just use that range, like this.

For Each cell In ws.Range("E2:E152")

HTH
Cal

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...