Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default 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





  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code the Macro to save and close a file? Eric Excel Discussion (Misc queries) 7 June 10th 07 03:28 PM
recrding macro,copy data thn close file, get messge abut clpbord PaddyBoy Excel Discussion (Misc queries) 2 October 25th 06 04:38 AM
Using Macro to Save Copy of File to New Location Chris Z Excel Discussion (Misc queries) 3 September 12th 06 11:26 PM
creat a macro to save a copy with different file name yrndtn Excel Discussion (Misc queries) 2 September 8th 06 01:14 PM
File close excel does not ask me to save changes Cathy Humphreys Excel Discussion (Misc queries) 2 June 13th 05 08:48 PM


All times are GMT +1. The time now is 04:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"