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

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,592
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:

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Johnny C

Well-known Member
Joined
Nov 7, 2006
Messages
1,003
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:

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,592
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Thanks Johnny C,
I will give this a go and play around with timings etc.
thanks
for the input :)
Tony
 

Watch MrExcel Video

Forum statistics

Threads
1,113,836
Messages
5,544,596
Members
410,623
Latest member
RusHartley
Top