How to close a excel file using Macro coding?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Once I open the file 1.xls, and try to run following Macro.
There is an error message "Array exceeds the range" [Translation from Chinese]

Sub Eric()
Workbooks("E:\1.xls").Close
End Sub

Does anyone have any suggestions what wrong is the above code? and how to
fix it?
Thanks in advance for any suggestions
Eric
 
Workbooks("1.xls").Close

You don't specify the drive and path when you use that workbooks(...)
collection.
Once I open the file 1.xls, and try to run following Macro.
There is an error message "Array exceeds the range" [Translation from Chinese]

Sub Eric()
Workbooks("E:\1.xls").Close
End Sub

Does anyone have any suggestions what wrong is the above code? and how to
fix it?
Thanks in advance for any suggestions
Eric
 
I already specify the drive and path, but it still does not work.
Does anyone know how to solve this coding for closing a file?
Thank for any suggestions
Eric

Dave Peterson said:
Workbooks("1.xls").Close

You don't specify the drive and path when you use that workbooks(...)
collection.
Once I open the file 1.xls, and try to run following Macro.
There is an error message "Array exceeds the range" [Translation from Chinese]

Sub Eric()
Workbooks("E:\1.xls").Close
End Sub

Does anyone have any suggestions what wrong is the above code? and how to
fix it?
Thanks in advance for any suggestions
Eric
 
Don't specify the drive and path.

Do NOT specify the drive and path.
I already specify the drive and path, but it still does not work.
Does anyone know how to solve this coding for closing a file?
Thank for any suggestions
Eric

Dave Peterson said:
Workbooks("1.xls").Close

You don't specify the drive and path when you use that workbooks(...)
collection.
Once I open the file 1.xls, and try to run following Macro.
There is an error message "Array exceeds the range" [Translation from Chinese]

Sub Eric()
Workbooks("E:\1.xls").Close
End Sub

Does anyone have any suggestions what wrong is the above code? and how to
fix it?
Thanks in advance for any suggestions
Eric
 
Thank everyone for suggestions

The following code is created under Report.xls
When I open Report.xls, then go to tools>Marcro, select Updating and click
RUN button, then it opens 1.xls file, save it and close it.
However, when I open Report.xls, use the hot key Ctrl+Shift+u, it is still
able to open 1.xls file, but it does not able to save it and close it.
Do you have any suggestions what wrong it is when I use the hot key to run
macro?

Sub Updating()
' Ctrl+Shift+u for hot key
Workbooks.Open Filename:="C:\files\1.xls", UpdateLinks:=3
Workbooks("1.xls").Activate
Workbooks("1.xls").Save
Workbooks("1.xls").Close
End Sub

Thank everyone very much for suggestions
Eric

Dave Peterson said:
Don't specify the drive and path.

Do NOT specify the drive and path.
I already specify the drive and path, but it still does not work.
Does anyone know how to solve this coding for closing a file?
Thank for any suggestions
Eric

Dave Peterson said:
Workbooks("1.xls").Close

You don't specify the drive and path when you use that workbooks(...)
collection.

Eric wrote:

Once I open the file 1.xls, and try to run following Macro.
There is an error message "Array exceeds the range" [Translation from Chinese]

Sub Eric()
Workbooks("E:\1.xls").Close
End Sub

Does anyone have any suggestions what wrong is the above code? and how to
fix it?
Thanks in advance for any suggestions
Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top