Save Workbook Copy To Same Path As Original

Aug 27, 2007

I'm trying to save a copy an excel file in the same directory of the original file. The code is pretty standard but it does not work if the file is stored in C: (only c: ) Is that a bug or am I doing something wrong? Anyways here is the code in case someone is interested in trying it out:

Sub CreateCopy()
ChDrive ThisWorkbook.Path
ChDir ThisWorkbook.Path
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls", _
InitialFileName:="CMS_" & Format(Now(), "mm-dd-yyyy"))
If fileSaveName <> False Then
MsgBox "Backup copy saved as: " & fileSaveName
End If
End Sub

View 5 Replies


ADVERTISEMENT

SaveAs - Copy Sheet Into New Workbook And Save It In Same Folder As Original Workbook

Jun 17, 2014

I have been trying to edit a code which previously saved a copy in a new workbook to a specific folder/path. (Additionally it copies and clears some figures, but this is working as it should.)

However I would like the copy to be saved at the same location as the original workbook, regardless of the path the original workbook is saved.

I.e if I need to move the workbook containing the code to a new folder/location, when using the macro, the new copy should be stored in the same folder/location as the original one.

For now it is only saving the copy into "My Documents"

Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 16-02-2009 by ceng
'

Sheets("Bunker ROB").Select
Sheets("Bunker ROB").Copy
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & Range("D3"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

[Code] ........

View 2 Replies View Related

Save Copy Of Workbook Without Closing Original

Jun 14, 2008

I want to have a user press a button on a worksheet page to save a copy of the workbook (and be able to name it and choose where to save it to) without closing or modifying the original. Note that if you "save as" manually it renames the workbook and closes the original.

View 7 Replies View Related

Delete Original Workbook After Save As

Mar 21, 2008

I don't believe this is possible but I've been wrong before.. Is it at all possible to Kill the current workbook using VBA? I " saved as" in another location and do not wish to keep the current workbook.

View 3 Replies View Related

Save CSV As New Copy & Delete Original

Apr 20, 2008

I was wondering if it is possible to have a macro running that will automatically save a .csv file to specific location and close the file. I would like to have the macro running so that as the files are opened they will be automatically saved to this location.

View 2 Replies View Related

Save Sheet With Same Path As Source Workbook

Dec 28, 2006

I've go a shared Workbook, which will be distributed among several users and stored in different places. The workbook uses the following

Sub savemeas()
Worksheets("data").Visible = True
Sheets("data").Copy
Application.DisplayAlerts = False
ActiveWorkbook. SaveAs Filename:="d:" & Range("a1").Value, _
FileFormat:=xlText, CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=True
End Sub

to save the sheet "data" as a text file with a name based on the value of cell a1. All I need is to modify the code so that the target path would not be

ActiveWorkbook.SaveAs Filename:="d:" & Range("a1").Value

but be the same as the source Workbook's - so that I wouldn't have to modify the code for each user separatly, because the sheet would alwayas be saved in the same folder as the current path of the source workbook.

View 4 Replies View Related

Default Save As To Workbook Drive & Path

Jan 5, 2008

Excel 2002 SP3

When a file is currently open, and the user selects "Save as", it takes them to the files native directory. (Where it was last saved).

If the user has that same file open, opens another file from a different directory, goes back to the first file and selects "Save as", it takes them to the location where the last file was opened from.

View 9 Replies View Related

Save Copy As Same Path And Name

Jul 1, 2008

I want a Macro which will copy my workbook and paste it into a new workbook. Then it will automatically save it under the SAME name as the original and the SaveAs Box must show up (for cosmetic fixes). It is important it asks if it wants to save it under the same name. Example: My file is called "Summary_2008" and when I hit the Macro it will do those things and it will ask me if I want to save it in the SAME directory under the name "Summary_2008" (I will only add a number then).

(The macro must know how to read the original name since I have 7 possible filenames - it depends on which company I choose, that is why it is important it is saved under the same name)

Sub Zamenjaj()
Worksheets.Copy
Dim WS As Worksheet
For Each WS In Worksheets
Zadnja_vrstica = WS.UsedRange.Rows.Count
Zadnji_stolpec = WS.UsedRange.Columns.Count
For rwIndex = 1 To Zadnja_vrstica
For colIndex = 1 To Zadnji_stolpec
With WS.Cells(rwIndex, colIndex)
If WS.Cells(rwIndex, colIndex).HasFormula Then..........................

View 3 Replies View Related

Create & Save Workbook To Same Path As Macro File

Aug 21, 2008

I have code to create a new workbook, and when I try to rename it I get "Compile error: Can't assign to read-only property."

Dim objXlApp As Object
Dim wkb As Workbook
Dim wks As Worksheet
Set objXlApp = CreateObject("Excel.Application")
' Create a workbook
Set wkb = objXlApp.Workbooks.Add
' Delete all worksheets bar the first one.
For Each wks In wkb.Worksheets
If Not wks.Index = 1 Then
wks.Delete

End If
Next wks
'Create some worksheets and names
With wkb
.Worksheets(1).Name = "myWorksheet1"
.Worksheets.Add.Name = "myWorksheet2"
.Worksheets.Add.Name = "myWorksheet3"
.Worksheets.Add.Name = "myWorksheet4"
End With...................................

View 5 Replies View Related

Macro To Save Workbook By Referencing Cell In Another Workbook For File Name And File Path

Mar 21, 2013

I have got a master workbook and I have written macro to copy and paste data on another workbook. write a macro to save the new workbook to a file path with a file name where both file name and path are stored in master workbook sheet...

View 5 Replies View Related

How To Copy A Worksheet, WITHOUT Linking It To The Original Workbook?

Sep 27, 2008

A simple one for you, but again my Google skills seem lacking. This must be common practice but until one knows the key combination...

I have created a summary sheet with lots of formulas which analyse other sheets in a workbook. I want to copy this summary sheet to a seperate workbook to use as a template.

Of course, the copying process always links the new (template) sheet to the original workbook it was copied from. How does one copy without forging this link? All I want are the formulas copied across totally unchanged; I really *don't* want to manually edit 50 or so formulas!

View 7 Replies View Related

Create Copy Of Workbook Without Closing Original

Dec 3, 2007

I would like to create a copy of an open workbook.

Workbook.SaveAs would seem to be a possibility, but this closes the original workbook - I need to keep the original workbook open as well as the workbook it has been "SavedAs".

I do not want to close the first workbook and repoen it as there are instances where it may be protected and I do not want the user to have to reinput any passwords etc.

View 9 Replies View Related

Copy Sheet To Same Workbook Without Overwriting Original

Aug 11, 2007

I have some code written to duplicate a template and rename the copy to "Working Copy".

But if I run the code more than once, it breaks as VBA tries to overwrite the sheet with the same name.

Would I would like is for the macro to check to see it already exists and duplicate the copy with some type of incremental integer. Thus the first duplicate would be Working Copy 1, and if the macro is run again, the duplicated copy would be Working Copy 2, etc.

here is what I have so far:

Sub SCButton()
Dim i As Integer 'for making Working Copy 1, 2, etc.

Sheets("SCTemplate").Select 'this file will eventually be hidden and thus the user with only see the wokring copies.
Sheets("SCTemplate").Copy After:=Sheets(4)
Sheets("SCTemplate (2)").Select
'some sort of If statement here to check for the sheets

Sheets("SCTemplate (2)").Name = "Calculation"

View 5 Replies View Related

Create Copy Workbook With Cell Referencing To Original?

Apr 15, 2014

At my work we are using Excel as a CMS to produce SQL scripts for insertion into a database. The data is then turned into mobile web pages. This involves multiple workbooks - 1 for each main page with the sub-pages as extra worksheets in the book.

Much of the data is duplicated so we have created master workbooks then copied them and laboriously referenced the relevant cells back to the original. That way if any data in the master is changed, all copies will change simultaneously.

This is obviously not the most efficient way of publishing web pages but we are stuck with it for now. So I am wondering if it is possible to write a VBA code to create a copy of the master and then reference all required tables in the worksheets automatically? The tables are all named ranges.

View 9 Replies View Related

Save Hyperlink Path For File With Absolute Path And Non-Relative?

Mar 4, 2013

is it possible to configure Excel in order to save the Hyperlink path for a file with absolute path and non relative?

I notice that the hyperlink is ....pdf ry.pdf

if I change the position of the file excel there is a problem!

I would like to save es. d:invoichepdf ry.pdf

View 1 Replies View Related

How To Copy Module(s) To Workbook In Different Path

Jun 21, 2013

Want to Copy a Module(s) to another workbook in a different path and also password protect it at the same time using VBA.

I need to copy some Module(s) from One WorkBook to another using VBA..

I have used the following code to good effect, however my TargetWb is not at the same path, so I need some modification in this code if that's possible and also this VBA Module which is Copied and Pasted in the Target WOrkbook needs to be Password Protected so that it cannot be tampered.

The code which I'm using currently is:

Code:

Sub CopyModule(SourceWB As Workbook, strModuleName As String, _
TargetWB As Workbook)
' copies a module from one workbook to another
' example:
' CopyModule Workbooks("Book1.xls"), "Module1", _

[Code]...

Code:

Sub Try()
Call CopyModule(Activeworkbook, "Module1", TargetWb)

on this to pass the TargetWb as a variable which can be generated in the code used for generating the File using a Macro..

End Sub

In the above code The SourceWB would be the ActiveWorkbook and the Target Workbook is the file created using another Macro from several sheets of the Active Workbook and its created in a folder with a specific name and therefore the Path is one more level inside than the Active Workbook.

if the Transferred Module can be Passworrd Protected and Locked for editing..for the end user.

View 9 Replies View Related

Macro To Copy Folders To Path Of Open Workbook Based On Cell Values

Aug 3, 2014

I have an Excel sheet that contains a few thousand folder paths in the first column. The first few cells in the column look similar to below.

C:UsersNameDesktopFolder Copy12010360
C:UsersNameDesktopFolder Copy12010361
C:UsersNameDesktopFolder Copy12010362
C:UsersNameDesktopFolder Copy12010363
C:UsersNameDesktopFolder Copy12010364
C:UsersNameDesktopFolder Copy12010365

I am trying to create a macro that will copy any folders that exist in any of the paths listed in the first column. The folders should be copied to the path of the open workbook containing the macro. Below is the macro I have currently, much of which was taken from information I found in this thread [URL]....

VB:

Sub wrapper3()
x = 1
Set fs = CreateObject("Scripting.FileSystemObject")
While Sheets("Air").Cells(x, 1) <> ""
v = InStrRev(Sheets("Air").Cells(x, 1), "")
dest = ActiveWorkbook.Path & Mid(Sheets("Air").Cells(x, 1), v, 99)

[Code]...

This code seems to work fine if all of the folders exist to be copied. My problem is that some do not and it is creating a "Path Not Found" error for which I need a fix. If the folder doesn't exist at the path nothing should be copied and the next path can be evaluated.

View 2 Replies View Related

Open Workbook Where Named Cell Contain Name & Path, Copy Range And Paste Values

May 19, 2009

I am successfully opening a .csv file using a variable value stored in a named range in my Main file (the variable includes the directory and path).
I copy data from the .csv file to the Main file then I need to close the .csv file without saving but I want to do that by using the

Windows("xxxx").Activate

command where "xxxx" is the namedrange in my Main file which stores the .csv filename (without the directory and path prefix).

I can use the

ActiveWindow.ActivatePrevious

command but if I have another workbook open, this one closes instead of the .csv file I opened from the macro.

I realise this is probably very basic and I've searched the forums but can't find any identical postings.

View 5 Replies View Related

Copy Of Active Workbook Path Stamped Onto Spreadsheet With Date And Time / Edit Check

Feb 1, 2010

1) I need to add an edit check
2) have a copy of Active Workbook Path stamped onto spreadsheet with date and time to create a visual record of where the file has been saved (described after the code below).

1) I need to verify that two cells (S7 and S9) are not blank before running my code below (=IF(OR(S7<>"",S9<>""),RUN CODE,"You must select your Provider or Division before you can save this document")).

- If both of these cells are blank a message box should notify the user that they must select the provider and/or division before they can continue with the save.

- If one or more of these cells are not blank the code below should run.

View 3 Replies View Related

Save As With New Name - But Keep Old File Intact - With Original Name

May 7, 2013

How does one do a save with a new name while keeping the original file intact - with the original file name? Would a macro be required?

View 1 Replies View Related

Save The Tamplate In Original Place

Aug 27, 2008

I have VBA program that collect the data from database and make a report.(I will mention I open the browser to look for database )
Here is a problem:
My original file is " Daily Report.xlt(template) " .At the begin when I open this file ,the file name appear as a " Daily Report1 "...This is not big deal
When I run macros I need to keep some info on the original file.
After I done, I have following code to save as " Daily Report.xlt " .
but the actual problem is ;the code save this file on the database path that I don't want it.Actually I want to overwrite on original file to keep that file up to date.Here is code
ActiveWorkbook.SaveAs Filename:= _
"Daily Report.XLT", _
FileFormat:=xlTemplate, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Note:I know I can add the path in front of the file name and save it in the that directory .Different customer different path I can not use fix directory.

View 9 Replies View Related

Macro To Save Sheet With Same Page Breaks As Original

May 14, 2009

I am trying to sort a macro out to save my sheet the same as the original when the button is clicked. When i try it from one location it is fine but from another location i get a print error, the error says prit quality is not right, when i debug it highlights: Print Quality = 600 I have tried changing it but keep getting the same error. Their maybe an easier way to do this but not being very good on VB i dont know what to do. This file is on a server and will be accessed from different locations.

View 2 Replies View Related

Importing Data To New Workbook Locks Original Workbook For Editing

May 24, 2006

I have created a workbook that imports data from another workbook which is used frequently on a network drive. After I import the data to my new workbook, it locks the original workbook for editing. Is there a property that will allow me to disable this 'locked for editing' read only mode or any other way to get around this?

View 6 Replies View Related

VBA To Copy Worksheet To New Workbook And Save

Oct 19, 2011

How to copy the entire worksheet into a new workbook and save the file to a specific directory with the following filename format ("exceptions191011 - ie. the word exceptions followed by today's date in ddmmyy format).

Here is what I've got so far:

Code:

Sub SaveAs()

Dim FName As String
Dim FPath As String

FPath = "G:Exceptions"
FName = "Exceptions" & Format(Date, "ddmmyy") & ".xls"

Sheets("DataSort").Copy
ThisWorkbook.Sheets("Sheet1").SaveAs Filename:=FPath & "" & FName

End Sub

How to add the following condition that if a file already exists with that name then to bring up an error message stating the file already exists? As well as save the new workbook, it appears to close the original workbook - can I stop this?

View 3 Replies View Related

Save Workbook As Copy To Another Directory

May 20, 2009

I need save my workbook as copy to another directory, ( C: ) with VBA code

View 9 Replies View Related

Save A Copy Of The Open Workbook

Dec 4, 2009

I know that the line in my code Worksheets.Copy is NOT what I need to have to make this work, but with it it's the closest I could get to what I want.

I want the user to be able to click the SAVE command button, be allowed to either accept or change the default save options, save the current workbook and then go right back to the form that has the SAVE command button. Sounds simple, I know, but when you don't know the right commands to save the WORKBOOK, not just the WORKSHEETS, it becomes a P.I.A.

I know there's a lot there, but here's my code, which is just a slightly altered version of the code by Ron de Bruin:

Private Sub SaveData_Click()

'If no date has been selected then don't allow SAVE
If PubDateLabel.Caption = "" Then

MsgBox "Publication Date not set. You must select a date before saving.", vbCritical, "No Publication Date!"
Exit Sub

End If

View 9 Replies View Related

Copy Values Only To New Workbook & Save

Sep 8, 2006

i need to copy from one workbook to another at present i have formulars in columns a b c d e g in f and h the is data that could go to f and h100 these are not formulars

i need to be able to copy the data from a1 to the last cell with data in it in column A to the same row in column h

View 9 Replies View Related

Copy Worksheet To New Workbook & Save

Oct 18, 2006

I have a workbook with a worksheet named "Report"... this sheet and it's macros generate a report from data on another sheet. I'm adding a button to copy the (filled) Report sheet to a new workbook, rename the new sheet in the new workbook "Rep[Name]", then save and close the new workbook. I've recorded a maco of me doing these tasks manually, but what's recorded seems very generic, and does not seem to specify what's really occurring...

For example (in part);
> Rightclick on the Report tab
> Move or Copy
> To Book: (new book)
> [x]Create a Copy
> [OK]

yields:

Sub Macro1()
Sheets("Report").Select
Sheets("Report").Copy
End Sub

This recorded macro does not specify (new book), or Before:"Sheet1" as was the result of my actions... and when replayed back, only makes a copy in the active workbook, before the active sheet...

View 4 Replies View Related

Macro To Copy Rows To New Workbook And Save?

Mar 9, 2012

I'm looking for a macro that can do the following:

Contact
First Name
BD
Case
XXXXXXX
Aaron
A
XXXXXXXXXXXXXXX
XXXXXXXX
Abigail
C
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
Accounts
D
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
Adam
C
XXXXXXXXXXXXXXX

Filter by BD 'C'

Copy all rows containing 'C' to new workbook.

Save new Workbook as 'Mailing C.xls' and close to specific flolder.

View 7 Replies View Related

VBA To Copy Multiple Sheets Into New Workbook And Save

Jun 23, 2014

I have managed to pull together code that does the required task - save two sheets from a work book in to a new workbook on to a dorectory each day. However I woul;d liek to paste special the values and cannot figure our how to reference that on the below:

'saves text file in day on day folder
Dim WS As Worksheet, CheminDest As String, fNAME As String
'create directories as needed
On Error Resume Next
CheminDest = "T:DMRatesReportsChecks" & Year(Date) & ""

[Code] ..........

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved