0

I'm having an application made with vba. Occasionally a sheet is exported as a pdf file on a network hard drive, overwriting an existing pdf file. If the pdf file is open on a computer, there's an error message when you try to export it. Is it possible to export it (update the pdf file) while it's opened on another computer? It's always a hassle to find where it's open, it interrupts the workflow greatly.

This is the code:

sht.Visible = xlSheetVisible
sht.ExportAsFixedFormat xlTypePDF, _
"G:\Info\DontSell.pdf", _
xlQualityStandard, True, False
sht.Visible = xlSheetHidden
Jens
  • 183
  • 1
  • 10
  • 1
    Your question is not too clear, I am afraid... What do you mean by "when you try to save it"? Do you mean, when try exporting as fixed format using **the same name as an open pdf file**? If so, it is obvious that you cannot export it, independent of the place where the open file exists. You can only check if the file is open and wait to be closed, or save it with a different name. If not, please better clarify what you try accomplishing and in which circumstances the error is raised. – FaneDuru Dec 05 '22 at 08:59
  • I'm trying to export it as fixed format using the same name as a pdf file that already exists. Basically overwriting the pdf file. If the file is opened then that throws the error message. – Jens Dec 05 '22 at 09:06
  • 1
    I would also like having money as Bill Gates has... It is not possible to overwrite an open pdf file! – FaneDuru Dec 05 '22 at 09:20
  • If the file is open then you can't replace it. Check if the file is open before exporting it. You can use the method shown [HERE](https://stackoverflow.com/questions/9373082/detect-whether-excel-workbook-is-already-open) to check if the pdf file is open – Siddharth Rout Dec 05 '22 at 09:23
  • Ok. Thanks for the answers! Maybe I'll export it as a picture then, or a text file, or something else. I'll have to investigate! :) – Jens Dec 05 '22 at 09:28
  • Except the text file, you will face the same issue with all the other types, I'm afraid... – FaneDuru Dec 05 '22 at 09:33
  • maybe everytime you save to pdf of the newer version, set that pdf file attribute to read only. But since I never implement it, so I'm not for sure if another computer open/view that read only pdf file, the other computer can still export to pdf (new version) to that same read only pdf which being opened/viewed by other computer. – karma Dec 05 '22 at 09:48
  • 1
    If you open the pdf with chrome, you will be able to overwrite it while open. – Kostas K. Dec 05 '22 at 10:35
  • @KostasK. Thank you, that is actually helpful. I'll just tell people to open in the web browser! That solves the problem! – Jens Dec 05 '22 at 10:37

0 Answers0