Workbook check - exist or not

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Hi All,
Im getting an error on red line. Error - Invalid inqualifier. can any one please help
Code:
If myFileExists("\\inmum-i-fs4\group$\WNA Skyline\Common\" & [COLOR=#ff0000]Uname[/COLOR].xls) Then
Workbooks.Open Filename:="uname.xls", UpdateLinks:=False
Worksheets(Uname).Select
Else
Set NewWb = Workbooks.Add
Application.Dialogs(xlDialogSaveAs).Show
NewWb.Save
NewWb.Close
End If
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this.
Code:
If myFileExists("\\inmum-i-fs4\group$\WNA Skyline\Common\" & Uname  & ".xls") Then
 
Upvote 0
Hi Norie, This is working Thanks..
Here I dont want to ask dialog window to save workbook. Instead if workbook is not available then it will save the new workbook in the given path which I have given..
Can you pls guide this too..

Try this.
Code:
If myFileExists("\\inmum-i-fs4\group$\WNA Skyline\Common\" & Uname  & ".xls") Then

Save workbook as name of Apllication.User. Thanks
 
Last edited:
Upvote 0
Hi Norie,
Got something like this
Code:
path = "\\inmum-i-fs4\group$\WNA Skyline\Common\"
ActiveWorkbook.SaveAs Filename:=path & "\" & Uname


I have tested the below code now, and I found even though workbook exist with the user name it again creating new book..
Code:
Sub newWBcreate()
Dim Uname As String, path As String
Uname = Application.UserName
If myFileExists("\\inmum-i-fs4\group$\WNA Skyline\Common\" & Uname & ".xls") Then
Workbooks.Open Filename:="uname.xls", UpdateLinks:=False
Worksheets(Uname).Select
Else
Set newWB = Workbooks.Add
path = "\\inmum-i-fs4\group$\WNA Skyline\Common\"
ActiveWorkbook.SaveAs Filename:=path & "\" & Uname
Sheets("Sheet1").Select
ActiveSheet.Name = Uname
newWB.Save
newWB.Close
End If
End Sub


And this is Function who checks for workbook..
Code:
Function myFileExists(ByVal strPath As String) As Boolean
'Function returns true if file exists, false otherwise
    If Dir(strPath) > "" Then
        myFileExists = True
    Else
        myFileExists = False
    End If
End Function
 
Last edited:
Upvote 0
Hi Norie, Got the solution. Mistake was file type.
I have taken .xls, it should be actually .xlsx
thanks..
 
Upvote 0
Hey Norie,
On the same code, instead of creating new workbook, Is it possible to create copy of workbook which is exist on that location..
Many Thanks..

Try this.
Code:
If myFileExists("\\inmum-i-fs4\group$\WNA Skyline\Common\" & Uname  & ".xls") Then
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top