nigelandrewfoster
Well-known Member
- Joined
- May 27, 2009
- Messages
- 747
Hello
My macro creates a PDF file (printing to, as it happens, Bullzip, a PDF Printer) called "To Email"
It then renames the file to a unique and useful name
However... It is frequently trying to
a) Create another file called "To Email" whilst the previous file is still called "To Email" or
b) Rename the file "To Email" when it has already been renamed.
I have tried many solutions. The only one that has worked is to create an arbitrary Application.Wait before AND after the rename. Got caught out this afternoon when installing onto a very slow PC. I have no way of knowing how long it should wait - in short, it's a cludge.
My simple solution does not work. Why?
This leads to File path access error at the highlighted line. When I hit CONTINUE, it works ok - so AGAIN it must be a timing error. Can someone explain why? And better still, a concrete solution? Some of my clients still use 2003, hence my need to use an external PDF creator. It's only the timing that I need help on, it works fine otherwise.
Many thanks
Nigel Foster
My macro creates a PDF file (printing to, as it happens, Bullzip, a PDF Printer) called "To Email"
It then renames the file to a unique and useful name
However... It is frequently trying to
a) Create another file called "To Email" whilst the previous file is still called "To Email" or
b) Rename the file "To Email" when it has already been renamed.
I have tried many solutions. The only one that has worked is to create an arbitrary Application.Wait before AND after the rename. Got caught out this afternoon when installing onto a very slow PC. I have no way of knowing how long it should wait - in short, it's a cludge.
My simple solution does not work. Why?
Code:
Function Invoice_Exists() As Boolean Dim strFilename As String
strFilename = Worksheets("Workpad").[b1] & "NEW INVOICES\FOR EMAILING\To Email.pdf"
If Dir(strFilename) <> "" Then Invoice_Exists = True
End Function
Code:
Sub Rename_File
Do
Loop Until Invoice_Exists()
[B] Name Worksheets("Workpad").[b1] & "NEW INVOICES\FOR EMAILING\To Email.pdf" As Worksheets("Workpad").[b1] & _[/B]
[B] "NEW INVOICES\FOR EMAILING\" & CName & Cpy & ".pdf"[/B]
Do While Invoice_Exists()
Loop
End Sub
This leads to File path access error at the highlighted line. When I hit CONTINUE, it works ok - so AGAIN it must be a timing error. Can someone explain why? And better still, a concrete solution? Some of my clients still use 2003, hence my need to use an external PDF creator. It's only the timing that I need help on, it works fine otherwise.
Many thanks
Nigel Foster