VBA Hide / Disable a File Alert

Thank you for looking at my question,

I am using the code below to create a workbook on a mapped drive.

    ''''' Open Workbook Named After Project '''''
    'Workbooks.Open "C:\Projects\" & strProject
    Workbooks.Open "O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)
    Application.DisplayAlerts = False

    If Err.Number = 1004 Then
        Set wbDest = Workbooks.Add
        Application.DisplayAlerts = False
        wbDest.SaveAs Filename:="C:\Projects\" & strProject
        wbDest.SaveAs Filename:="O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)
        'Application.DisplayAlerts = True
        Application.DisplayAlerts = False
    Else
        Set wbDest = ActiveWorkbook
    End If
    On Error GoTo 0
   
When the code runs I get a message "Sorry, we couldn't find...." - when I click OK the file is created if it doesn't exist already.

I don't get the message when I point the code at my local C: drive

Please can anybody tell me how I prevent the message appearing when pointed at the mapped drive?
Gary CroxfordOperations Support AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try it like this and see if that makes any difference.....

Application.DisplayAlerts = False
On Error Resume Next
Workbooks.Open "O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)

    If Err.Number = 1004 Then
        Set wbDest = Workbooks.Add
        wbDest.SaveAs Filename:="C:\Projects\" & strProject
        wbDest.SaveAs Filename:="O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)
    Else
        Set wbDest = ActiveWorkbook
    End If
    On Error GoTo 0
    
    Application.DisplayAlerts = True

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
1.  does it give you an error number?
2.  does the message actually terminate with "...." or are you just abbreviating?  If abbreviating, take a screen shot of the error message and post it here.

3.  I've never tried actually creating the excel file by attempting to open a file that doesn't exist.
strFileName = "O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)
debug.print strFileName
Workbooks.Open strFileName

Open in new window

but if you are trying to check to see whether the file already exists, I would try:
strFileName = "O:\Project Part Planning\" & Left(wbSource.Sheets("Analysis").Range("A2"), 9)
debug.print strFileName
if dir(strFilename) <> "" Then
    set wbDest = Workbooks.Open strFileName
Else
    Set wbDest = Workbooks.Add
    wbDest.SaveAs strFileName
end if

Open in new window

Gary CroxfordOperations Support AnalystAuthor Commented:
sktneer, thank you, works fine
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Crxfrd!
Glad it worked for you. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.