Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macro to save and close, then copy file
I've created a button with a macro assigned to it. I'm trying to save and
close an Excel file, then close the application. Then I would like to copy it to another location (to do a type of sync operation). The user would click the button each time they make changes. The code below is not copying the file to the new location. Can anyone help me? Thank you so much. Sub Rectangle1_Click() Dim FromFileName As String Dim ToFileName As String Workbooks("Book1.xls").Save Workbooks("Book1.xls").Close Application.Quit FromFileName = "C:\Ole\Book1.xls" ToFileName = "C:\Blue\Book1.xls" FileCopy Source:=FromFileName, Destination:=ToFileName End Sub |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macro to save and close, then copy file
Kind of hard for excel to do anything after closing...
-- Don Guillett Microsoft MVP Excel SalesAid Software "NewSysAdmin" wrote in message ... I've created a button with a macro assigned to it. I'm trying to save and close an Excel file, then close the application. Then I would like to copy it to another location (to do a type of sync operation). The user would click the button each time they make changes. The code below is not copying the file to the new location. Can anyone help me? Thank you so much. Sub Rectangle1_Click() Dim FromFileName As String Dim ToFileName As String Workbooks("Book1.xls").Save Workbooks("Book1.xls").Close Application.Quit FromFileName = "C:\Ole\Book1.xls" ToFileName = "C:\Blue\Book1.xls" FileCopy Source:=FromFileName, Destination:=ToFileName End Sub |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macro to save and close, then copy file
You're doing things out of order. Assuming your coding is in the workbook,
once you close the workbook, the coding is gone, and so it never reaches your final steps. Sub Rectangle1_Click() Dim FromFileName As String Dim ToFileName As String Workbooks("Book1.xls").Save FromFileName = "C:\Ole\Book1.xls" ToFileName = "C:\Blue\Book1.xls" FileCopy Source:=FromFileName, Destination:=ToFileName 'Since closing XL closes your workbook, 'no need for two lines of coding Application.Quit End Sub -- Best Regards, Luke M *Remember to click "yes" if this post helped you!* "NewSysAdmin" wrote: I've created a button with a macro assigned to it. I'm trying to save and close an Excel file, then close the application. Then I would like to copy it to another location (to do a type of sync operation). The user would click the button each time they make changes. The code below is not copying the file to the new location. Can anyone help me? Thank you so much. Sub Rectangle1_Click() Dim FromFileName As String Dim ToFileName As String Workbooks("Book1.xls").Save Workbooks("Book1.xls").Close Application.Quit FromFileName = "C:\Ole\Book1.xls" ToFileName = "C:\Blue\Book1.xls" FileCopy Source:=FromFileName, Destination:=ToFileName End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to code the Macro to save and close a file? | Excel Discussion (Misc queries) | |||
recrding macro,copy data thn close file, get messge abut clpbord | Excel Discussion (Misc queries) | |||
Using Macro to Save Copy of File to New Location | Excel Discussion (Misc queries) | |||
creat a macro to save a copy with different file name | Excel Discussion (Misc queries) | |||
File close excel does not ask me to save changes | Excel Discussion (Misc queries) |