A family of Microsoft word processing software products for creating web, email, and print documents.
It could be a timing issue and you might need to incorporate DoEvents to ensure that the file has been created before the code tries to rename it.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a macro that creates “prn file” then rename this prn file in the same directory from the the cell "C6" of the FRUIT Worksheets.
The macro does the following:
However, the filename is not renaming it and I get the window message below, highlighted in yellow as shown in the pictures below.
Obviously, the file “b” is no renamed (see the picture below)
Could you please support me to fix this error '53'
This is the macro:
'###########################################################
Sub MainAll()
Call ALLApples
Call ALLBananas
End Sub
Sub ALLApples()
Call A
End Sub
Sub A()
Set wd = CreateObject("word.application")
wd.Application.Documents.Open "C:\Apple\Apple1.docm"
wd.Application.Visible = True
wd.Application.Run "PrinterSelectionInWord.PrinterSelectionInWord"
Set wd = Nothing
End Sub
Sub ALLBananas()
Call E
End Sub
Sub E()
Dim oldName As String
Dim newName As String
'************************* Take the Cell Value from Excel *************************
Job = Worksheets("FRUIT").Range("C6")
'************************* Take the Cell Value from Excel *************************
oldName = "OLDFILE": newName = "NEWFILE" '
'************************* Rename the Filename ************************************
oldName = "C:\Bananas\PRN Files\B.prn": newName = "C:\Bananas\PRN Files" & Job & "_Banana_Yellow.prn"
'************************* Rename the Filename ************************************
Name oldName As newName '
End Sub
'###########################################################
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
It could be a timing issue and you might need to incorporate DoEvents to ensure that the file has been created before the code tries to rename it.
Doug,
I applied this statement before the code tries to rename it, as you advised me.
'**************************************************
Application.Wait (Now + TimeValue("0:00:15"))
'**************************************************
And IT IS WORKING PERFECTLY!!!!!
Thank you very much. I appreciate your support
Maperalia,
It could be a timing issue and you might need to incorporate DoEvents to ensure that the file has been created before the code tries to rename it.
Doug,
Thank you very much for your prompt response.
I have another question. Do I have to place the DoEvent between both macros?
Or where do you think is more effectively to locate it?
Thanks
Maperalia