Log in

View Full Version : [SLEEPER:] Kill and filecopy



chooriang
11-15-2019, 09:29 AM
I have following code on Excel MAC, trying to delete a word file and recreate it by copying it from template file.
But it seems the code fail.



On Error Resume Next
Kill strOutputPath
On Error GoTo 0
DoEvents

FileCopy strTemplatePath, strOutputPath
DoEvents

On Error Resume Next
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
wdApp.WindowState = 2
On Error GoTo 0
DoEvents


Set wdDoc = wdApp.Documents.Open(strOutputPath)




The code always fail at "Set wdDoc = wdApp.Documents.Open(strOutputPath)" on the first attempt if the file "strOutputPath" is exist.
On second attempt where the file "strOutputPath" is actually deleted on the 1st attempt, it can run without problem.

It worked well on WIN on the 1st attempt but not on MAC.
What's wrong with the code? How to handle this correctly on MAC?