ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro assigned to a button (https://www.excelbanter.com/excel-discussion-misc-queries/121847-macro-assigned-button.html)

Sadcrab

Macro assigned to a button
 
Is it possible for a macro to save a workbook in a new location and delete
the old location

Don Guillett

Macro assigned to a button
 
maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Is it possible for a macro to save a workbook in a new location and
delete
the old location




Sadcrab

Macro assigned to a button
 


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--

Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks

Dave Peterson

Macro assigned to a button
 
I think Don was just showing a sample so you could see how to use the Name
statement.

If you want to save an open workbook as a new name and then delete the original
workbook, you could do something like this (with absolutely no checks at all!):

Option Explicit
Sub testme()
Dim OldName As String
Dim NewName As String

NewName = "C:\changethistowhatyouneed\filename.xls"

With ActiveWorkbook 'or ThisWorkbook????
OldName = .FullName
.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End With

Kill OldName

End Sub





Sadcrab wrote:

"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--

Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks


--

Dave Peterson

Sadcrab

Macro assigned to a button
 
Thanks Dave,

What I would like to do is save the same workbook (with different data)
several times giving a new name to each saved workbook when moved. At the
moment using this macro will overwrite the last saved workbook and not give
me an option to save as and give a different name.

"Dave Peterson" wrote:

I think Don was just showing a sample so you could see how to use the Name
statement.

If you want to save an open workbook as a new name and then delete the original
workbook, you could do something like this (with absolutely no checks at all!):

Option Explicit
Sub testme()
Dim OldName As String
Dim NewName As String

NewName = "C:\changethistowhatyouneed\filename.xls"

With ActiveWorkbook 'or ThisWorkbook????
OldName = .FullName
.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End With

Kill OldName

End Sub





Sadcrab wrote:

"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--

Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks


--

Dave Peterson


Dave Peterson

Macro assigned to a button
 
Dim NewName as string
dim NewNamePfx as string
dim iCtr as long

newnamePfx = "C:\whateveryouwant\filename"

in some kind of loop

for ictr = 1 to 100
newname = newnamepfx & format(now, "yyyymmdd_hhmmss") & ".xls"
activeworkbook.savecopyas newname
next ictr

This saves 100 copies and includes the date/time in the filename.


Sadcrab wrote:

Thanks Dave,

What I would like to do is save the same workbook (with different data)
several times giving a new name to each saved workbook when moved. At the
moment using this macro will overwrite the last saved workbook and not give
me an option to save as and give a different name.

"Dave Peterson" wrote:

I think Don was just showing a sample so you could see how to use the Name
statement.

If you want to save an open workbook as a new name and then delete the original
workbook, you could do something like this (with absolutely no checks at all!):

Option Explicit
Sub testme()
Dim OldName As String
Dim NewName As String

NewName = "C:\changethistowhatyouneed\filename.xls"

With ActiveWorkbook 'or ThisWorkbook????
OldName = .FullName
.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End With

Kill OldName

End Sub





Sadcrab wrote:

"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks


--

Dave Peterson


--

Dave Peterson

Don Guillett

Macro assigned to a button
 
This does work. Just change oldfolder to your desired folder and oldname to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--

Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks




Sadcrab

Macro assigned to a button
 
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and oldname to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--

Thanks Don but I can't get it to work. I get a runtime error 53 File not
found more help on this please. Thanks





Don Guillett

Macro assigned to a button
 
I did provide an example. Perhaps you could give the info on the path and
file name for old and new??

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and oldname
to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File
not
found more help on this please. Thanks







Sadcrab

Macro assigned to a button
 
Don
I've changed the info as follows and created relevant directories:

Sub movefile()

OldName = "C:\Test\Active\Test1.xls"
NewName = "C:\Test\Complete\Test1.xls"
Name OldName As NewName

End Sub


"Don Guillett" wrote:

I did provide an example. Perhaps you could give the info on the path and
file name for old and new??

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and oldname
to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File
not
found more help on this please. Thanks







Don Guillett

Macro assigned to a button
 
And it didn't work??? I just created the same folders and file and moved it
with the macro.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Don
I've changed the info as follows and created relevant directories:

Sub movefile()

OldName = "C:\Test\Active\Test1.xls"
NewName = "C:\Test\Complete\Test1.xls"
Name OldName As NewName

End Sub


"Don Guillett" wrote:

I did provide an example. Perhaps you could give the info on the path and
file name for old and new??

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and
oldname
to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File
not
found more help on this please. Thanks









Sadcrab

Macro assigned to a button
 

No message on screen as follows:

Run-time error 75:

Path/File Access error


"Don Guillett" wrote:

And it didn't work??? I just created the same folders and file and moved it
with the macro.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Don
I've changed the info as follows and created relevant directories:

Sub movefile()

OldName = "C:\Test\Active\Test1.xls"
NewName = "C:\Test\Complete\Test1.xls"
Name OldName As NewName

End Sub


"Don Guillett" wrote:

I did provide an example. Perhaps you could give the info on the path and
file name for old and new??

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and
oldname
to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File
not
found more help on this please. Thanks










Sadcrab

Macro assigned to a button
 


"Don Guillett" wrote:

And it didn't work??? I just created the same folders and file and moved it
with the macro.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Don
I've changed the info as follows and created relevant directories:

Sub movefile()

OldName = "C:\Test\Active\Test1.xls"
NewName = "C:\Test\Complete\Test1.xls"
Name OldName As NewName

End Sub


"Don Guillett" wrote:

I did provide an example. Perhaps you could give the info on the path and
file name for old and new??

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...
Sorry Don I still can't get it to work can you supply an example

"Don Guillett" wrote:

This does work. Just change oldfolder to your desired folder and
oldname
to
your file name, etc. Then fire.

--
Don Guillett
SalesAid Software

"Sadcrab" wrote in message
...


"Don Guillett" wrote:

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub


--
Thanks Don but I can't get it to work. I get a runtime error 53 File
not
found more help on this please. Thanks











All times are GMT +1. The time now is 10:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com