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

tonywatsonhelp

Well-known Member
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:

Johnny C

Well-known Member
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:

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Macro to copy values across rows and transposing them and add the user id
    [FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Hi,[/COLOR][/SIZE][/FONT] [FONT=Times New...
Top