VBA script to generate PDF once sheet is calculated

iamrufus

New Member
Joined
Feb 19, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Morning everyone

First time on here,

Im very new to VBA so bare with me, what I am trying to achieve is have excel export my current PO sheet to a PDF once its been opened/calculated. I have the VBA to export to PDF in my module working as per the below.

Sub CreatePdf()
Dim ID As String
ID = Range ("E4).Text
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\Apps\" + ID + ".pdf", _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub

The problem I have is my excel sheet is populated from an export from another application, sometimes it takes 10 seconds and sometimes it takes 1 minute for all the cells to populate. What I would like is for my CreatePdf module to only run once all cells have been populated.

I have tried
Workbook_Activated
Workbook_Open

The Excel sheet won't populate until you actually see it on the screen, ive tried adding wait timers but that hasn't worked either.

The last thing I was going to try was to perhaps have a complete duplicate of my PO sheet. The export would be mapped to say sheet1 and then I would have a duplicate of my PO form on sheet2 which just uses formulas to calculate all the cells i.e cell A1 on sheet1 = cell A1 on sheet2. I would then use a Worksheet_Calculate event to look at all the cells to make sure they match and once they do run the CreatePdf module.

Feels a bit dirty but not done anything like this before. I hope this kinda makes sense.

Id be really grateful for any advice.

Thanks all
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,215,684
Messages
6,126,199
Members
449,298
Latest member
Jest

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