Problem to SaveAs line

Hi,
I did get
21q.png
due to SaveAs line below. Why?
    Dim Time0 As Boolean, cnt0 As Integer, File0 As String, Title0 As String, Window0 As String, RowID0 As String, Var1 As String, Var2 As String, Var3 As String, Var4 As String, Var5 As String, Var6 As String, Var7 As String, Var8 As String, Var9 As String, Var10 As String, Var11 As String
    Time0 = True: cnt0 = 1: File0 = Application.ActiveWorkbook.Path & "\Departure List (of People already left).xls": Title0 = "Departure List (of People already left)": Window0 = "Departure List (of People already left).xls"
    
Rep0:   'Windows(Window1).Activate
    'Debug.Print Window1
    'Application.Workbooks(Window1).Activate
    With ThisWorkbook.Worksheets("Main Sheet").Range("AJ1:AJ50000")
        Set c = .Find(Search0, LookIn:=xlValues)
        If Not c Is Nothing Then
        
            Var1 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 3).Value
            Var2 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 4).Value
            Var3 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 5).Value
            Var4 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 6).Value
            Var5 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 7).Value
            Var6 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 8).Value)
            Var7 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 9).Value
            Var8 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 16).Value)
            Var9 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 17).Value)
            Var10 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 19).Value)
            Var11 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 20).Value
            
            RowID0 = CStr(c.Row) & "CC"
            'Windows(Window0).Activate
            Application.Workbooks(Window0).Activate
            If cnt0 = 1 Then
                Set HOBook = Workbooks.Add
                With HOBook
                    .Title = Title0
                    .Subject = Title0
                    .SaveAs Filename:=File0, FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled
                    .Close SaveChanges:=False
                End With

Open in new window

LVL 12
HuaMin ChenProblem resolverAsked:
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.

Rgonzo1971Commented:
HI,

Is File0 consistent with FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled?

Regards
0
GrahamSkanRetiredCommented:
Have you tried
.SaveAs Filename:=File0, FileFormat:=xlOpenXMLWorkbookMacroEnabled

Open in new window

0
HuaMin ChenProblem resolverAuthor Commented:
Sorry, I still get
21r.png
 due to SaveAs line below
    Dim Time0 As Boolean, cnt0 As Integer, File0 As String, Title0 As String, Window0 As String, RowID0 As String, Var1 As String, Var2 As String, Var3 As String, Var4 As String, Var5 As String, Var6 As String, Var7 As String, Var8 As String, Var9 As String, Var10 As String, Var11 As String
    Time0 = True: cnt0 = 1: File0 = Application.ActiveWorkbook.Path & "\Departure List (of People already left).xls": Title0 = "Departure List (of People already left)": Window0 = "Departure List (of People already left).xls"
    
Rep0:   'Windows(Window1).Activate
    'Debug.Print Window1
    'Application.Workbooks(Window1).Activate
    With ThisWorkbook.Worksheets("Main Sheet").Range("AJ1:AJ50000")
        Set c = .Find(Search0, LookIn:=xlValues)
        If Not c Is Nothing Then
        
            Var1 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 3).Value
            Var2 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 4).Value
            Var3 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 5).Value
            Var4 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 6).Value
            Var5 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 7).Value
            Var6 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 8).Value)
            Var7 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 9).Value
            Var8 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 16).Value)
            Var9 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 17).Value)
            Var10 = CStr(ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 19).Value)
            Var11 = ThisWorkbook.Worksheets("Main Sheet").Cells(c.Row, 20).Value
            
            RowID0 = CStr(c.Row) & "CC"
            'Windows(Window0).Activate
            Application.Workbooks(Window0).Activate
            If cnt0 = 1 Then
                Set HOBook = Workbooks.Add
                With HOBook
                    .Title = Title0
                    .Subject = Title0
                    '.SaveAs Filename:=File0, FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled
                    .SaveAs Filename:=File0, FileFormat:=xlOpenXMLWorkbookMacroEnabled
                    .Close SaveChanges:=False
                End With

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

GrahamSkanRetiredCommented:
I now don't think my previous comment was useful.

It might be a problem with the folder or the fact that the file is already open elsewhere.
0
ste5anSenior DeveloperCommented:
Clean up your code first, this makes testing and debugging simpler..

Option Explicit

Public Sub Test()

  CreateNewHOBook "C:\Temp\Text.xlsm", "TEST1"
 
End Sub

Public Sub CreateNewHOBook(AFileName As String, ATitle As String)

  Dim HOBook As Excel.Workbook
  
  Set HOBook = Workbooks.Add
  HOBook.Title = ATitle
  HOBook.Subject = ATitle
  HOBook.SaveAs Filename:=AFileName, FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled
  HOBook.Close SaveChanges:=False
  Set HOBook = Nothing
  
End Sub

Open in new window

0
GrahamSkanRetiredCommented:
When the code fails, can you try saving it manually? If that fails, the message might be more useful.
0

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
HuaMin ChenProblem resolverAuthor Commented:
Thanks to all.

Sorry, how to ensure that the same WorkBook would be close, after having created it like
                Set HOBook = Workbooks.Add
                With HOBook
                    .Title = Title0
                    .Subject = Title0
                    '.SaveAs Filename:=File0, FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled
                    .SaveAs Filename:=File0, FileFormat:=xlOpenXMLWorkbookMacroEnabled
                    .Close SaveChanges:=False
                End With

Open in new window

0
ste5anSenior DeveloperCommented:
Please rephrase your question. "the same WorkBook" makes non sense in this context.
0
HuaMin ChenProblem resolverAuthor Commented:
I want to ensure that the created Workbook would be closed after having created it. How?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
After .SaveAs your open workbook is automatically renamed to the new name. You  then close it. There is no workbook open after that.
0
HuaMin ChenProblem resolverAuthor Commented:
Can you share the codes to close it?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Your code in #a42487490 does that already!?
0
HuaMin ChenProblem resolverAuthor Commented:
But I encounter
21t.png
due to SaveAs line below
            ...
            If cnt0 = 1 Then
                Set HOBook = Workbooks.Add
                With HOBook
                    .Title = Title0
                    .Subject = Title0
                    '.SaveAs Filename:=File0, FileFormat:=XlFileFormat.xlOpenXMLWorkbookMacroEnabled
                    .SaveAs Filename:=File0, FileFormat:=xlOpenXMLWorkbookMacroEnabled
                    .Close SaveChanges:=False
                End With

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Your last question here was "how to close", not "how to save", and I thought that part would have been solved?
File0 needs to contain the correct file extension for the type of workbook you want to store. You have used .xls, which does not work with current Excel releases and FileFormat:=xlOpenXMLWorkbookMacroEnabled. File0 should use .xlsm.
0
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 Office

From novice to tech pro — start learning today.