Can I get this macro to run all the code before opening the PDF?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a macro below that works great but looks ugly,
what i mean is it opens the pdf half way through the macro, so when you close the pdf it shows me a half loaded screen and a looks ugly before it runs the rest of the macro when everything looks great again.

So I was wondering

Is there a way i can get the macros to still run after its opened the pdf or open the pdf after its run the macros

now the macros clear and reset the page the pdf is created from so we need the macro to be created before the call comand as it is shown.

any ideas plaese?

Thanks

Tony


my code

Code:
Sub ExportAsPDF3() 'iu
Application.ScreenUpdating = False
Call SetPrintArea ''
    Sheets("Fee Proposal PDF").ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Sheets("Fee Proposal PDF").Range("AU51") & ".pdf", _
    OpenAfterPublish:=True
Application.ScreenUpdating = True
Sheets("Fee Proposal PDF").DisplayPageBreaks = False

Call Clear_New_Fee_Proposal1

Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Unfortunately there's no foolproof way. Excel doesn't 'handshake' with other applications, it fires off the Sheets("Fee Proposal PDF").ExportAsFixedFormat command then gets on with the next statement.

The only way is to add a forced delay, e.g.

For i = 1 To 5000: DoEvents: Next

I use a variable e.g. and set it to 5000 at the top so if it plays up I can quickly change it.
For i = 1 To intDoEventCount: DoEvents: Next

Code:
Sub ExportAsPDF3() 'iu
Application.ScreenUpdating = False
Call SetPrintArea ''
Sheets("Fee Proposal PDF").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Sheets("Fee Proposal PDF").Range("AU51") & ".pdf", _
OpenAfterPublish:=True
[B]For i = 1 To 5000: DoEvents: Next[/B]
Application.ScreenUpdating = True
Sheets("Fee Proposal PDF").DisplayPageBreaks = False

Call Clear_New_Fee_Proposal1

Application.ScreenUpdating = True
End Sub

Mine is used when copying charts to PowerPoint as Excel copies faster than PowerPoint pastes.

Opening a PDF however is trickier as there's going to be a much longer delay as the PDF loads and formats itself.
 
Last edited:
Upvote 0
Thanks Johnny C,
I will give this a go and play around with timings etc.
thanks
for the input :-)
Tony
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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