How to code the Macro to save and close a file?

G

Guest

Workbooks.Open Filename:="C:\Files\1.xls", _
UpdateLinks:=3
ActiveWorkbook.Save
ActiveWindow.Close
The command "ActiveWindow" cannot be performed, does anyone have any
suggestions on how change the code for specific file under specific
directory, such as
Save "C:\Files\1.xls" to replace the code ActiveWorkbook.Save
Close "C:\Files\1.xls" to replace the code ActiveWorkbook.Close

Thank for any suggestions
Eric
 
B

Bob Phillips

Set oWB = Workbooks.Open (Filename:="C:\Files\1.xls", _
UpdateLinks:=3)
oWb.Save
oWb.Close

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Here is a tiny example. Start in some workbook.

Want to open x.xls.
Want to update it.
Want to save x.xls
Want to close x.xls

Sub eric()
Workbooks.Open Filename:="C:\x.xls", UpdateLinks:=3
Workbooks("x.xls").Activate
Range("A1").Value = 21
Workbooks("x.xls").Save
Workbooks("x.xls").Close
End Sub
 
G

Guest

Thank everyone for suggestions

I try this by typing following codes into Macro,
but the command Save and Close cannot be performed.
Do you have any suggestions on how to fix this?
Thank everyone very much for any suggestions
Eric
 
B

Bob Phillips

Why? What happens? What messages do you get?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Set oWB = Workbooks.Open (Filename:="C:\Files\1.xls", _
UpdateLinks:=3)
oWb.Save
oWb.Close

Once the file is opened and get updated. There is no Save and Close actions
at all, and the file keeps open as it is.

Does it have anything wrong with the code?
Thank for any suggestions
Eric
 
G

Guest

Thank everyone for suggestions

I try following codes too,
Sub eric()
Workbooks.Open Filename:="C:\x.xls", UpdateLinks:=3
Workbooks("x.xls").Activate
Range("A1").Value = 21
Workbooks("x.xls").Save
Workbooks("x.xls").Close
End Sub

The file gets undated, but stop to perform save and close action
Do you have any suggestions?
Thank everyone for 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

Top