VBA Code To Generate Filename Without Actually Saving File

Jan 23, 2014

I have a file that I want to name based on content in certain cells. I.e. "Q-(text from cell G1)-(text from cell B7)-Date(mm_dd_yy)". I want to be able to specify the location where I save this file each time I try to save it, but I want it to update the file's name if any of the parameters have changed.

I have some code generated that does just about everything right except that it automatically saves a version of the file in the folder where the original is located even though it also brings up the dialog box and allows me to save it in another location.

Basically, I want to fix the code below so that it doesn't save what appears to be a backup file each time. Should I be using some sort of savecopyas?

Code:
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Add the quote # to the header
ActiveSheet.PageSetup.RightHeader = "Quote No. " & Range("G1").Value

[Code].....

View 6 Replies


ADVERTISEMENT

Moving Columns Of Data Into Another File And Saving File With New Filename?

Aug 30, 2013

I was wondering if there is a way to write a macro that will take an excel file that I have called Alldata and then have it copy the first two sheets to a new workbook named something else( FullSparameter_0) and then copy the name of the third and fourth sheet into the new FullSparameter_0 workbook and then copy column A-E from sheet dB Alldata.xls and paste it into the FullSparameter_0.xls workbook in the same dB sheet in the same spot. And do the same thing with the Phase Sheet. i know this sounds confusing, but im really new to the VBA stuff.

I just need 15 different files from the original Alldata.xls that will be named FullSparameter_0, FullSparameter_1, .., FullSparameter_14. but each file will have the same two first sheets, Setup Information and Cal Verification, and the same last two sheet names, dB and Phase, but then in the dB and phase sheets, it will copy over the next four columns of data. so in FullSparameter_0 it will have column A-E from sheet dB in Alldata.xls in the dB sheet in FullSparameter_0 (Same with the Phase Sheets). Then in FullSparameter_1 it will have column A and Columns F,G,H and I (for dB and Phase). In fullSparameter_2 it will have column A and then J,K,L and M. Each FullSparameter_X will have the exact same first two sheets and then the other columns for the last two sheets will be pasted into columns A-E in dB and Phase.

View 1 Replies View Related

Generate A 6 Digits Code Based On Filename And Time Of Generation?

Aug 20, 2009

I need to enter a revision string into a file.

Basically, I need to combine the filename and its generation time and then encode it into a string (i.e. a 6 digits HEX code or 6 digits using [0-9][a-z][A-Z]) so it would generate a pretty much unique revision number.

So, is there any function that you can think of that would do something similar?
If not, what is the best to tackle this?
Generate a CRC or md5sum?

What would be in your opinion a quick and efficient way to solve this tricky one?

View 10 Replies View Related

Write VBA Code That Will Generate Text File With ALL Changes Made To Excel File

Jun 4, 2012

Is it possible to write vba code that will generate a text file with ALL changes that were made to an excel file. Ex. If Cell A17 = "Monday, June 4, 2012" and a user updates Cell A17 to "N/A", I would like to know what the value was before and after the udpate was made.

View 8 Replies View Related

Have Code To Block Save But How To Keep Code In Workbook Without Saving The File

Aug 1, 2013

My company has files that are already in use. I don't know too many details about how they work, but somehow saving the file will screw it up and my boss has to go back and reset something or other to correct it. Obviously it's connected to some other software somewhere. The code below will block Save and Save-As. BUT how do I get the file to hold onto the code without actually saving the file after the code is added (since the file shouldn't be saved)?

VB:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
Cancel = True

[Code].....

View 1 Replies View Related

Delete Code When Saving The File

Jan 23, 2010

I have posted already the problem to delete the code when sending a sheet via email and I have found the solution to the problem.

I tried to do the same when saving the file to specific folder, but i am facing problem.

View 6 Replies View Related

Saving Filename From Cell Text

Nov 18, 2009

When the user goes to File, Save As, I would like the filename to be populated from the contents of cells B2 and B3, i.e. 11/18/09-23. Is this possible? Also in the same code, can I specify that I want the destination folder to be K:Sheets?

View 11 Replies View Related

Saving Filename From Cell Value In Sheet

Dec 2, 2011

I would like code to automatically save my spreadsheet with the name that is present in cell F4 of the activesheet. For example, I would like to save my file to desktop and cell F4 contains the text 'hitec 348'

View 5 Replies View Related

Auto Generate Save As Filename From Multiple Cell Data?

Sep 14, 2012

way for my engineers to save a field ticket with a certain name based on data from a couple of cells in the worksheet. Re: Auto generate "Save As" filename from text and tried to use some code posted in the thread, but I an still not having any luck.

What I want to do is create an active X button when clicked on, would save the workbook to a certain folder. I want the name to look like this:

SO1!M3_SO1!M6_SO1!H2.xls

This is what I have so far:

Private Sub SaveMe()
ThisWorkbook.SaveAs Filename:="C:usersdefaultdesktop" & Range("SO1!M3").Value & Format(Range("SO1!M3").Value, "text") & ".xls"
End Sub

Would I click "general" or "workbook" in VBA when I enter this code?

View 5 Replies View Related

Excel 2007 :: Add Suffix (1) To Filename When Saving?

Aug 29, 2012

I find, when performing a 'save as', xl puts in a default filename with a suffix (1), or (2), or (3) and so on, to the existing filename, after I have opened a file from MS Outlook. I had assumed it was because there was already an existing file in the default directory, and so it was creating another version, but no other files with the same name exist in the default directory being saved to, or on the remainder of my computer, so I don't understand why this occurs.

View 2 Replies View Related

Creating A Folder And Saving In It With A Filename Taken From Cell

Mar 21, 2009

I would like excel to create the folder C:/Bill if it doesn't already exist when I click save/save as option and save the workbook in it with a filename that is a combination of text/values in cells A1 and A2 on Sheet1. Better if the save as dialog box appears with this option selected so that I have to just click Save in the save as dialog box to save it in "C:/Bill".

View 9 Replies View Related

Macro For Saving Filename Based On Cell Content

Feb 3, 2009

Is it possible to create a macro attached to a button that allows me to save the workbook based on content of 2 cells in the workbook?

I like to save the workbook based on content of cell A4 that contend a text string. After that saving another time with the contend of cell A4 plus cell A9 which contend the today() function. I am doing this because this workbook is constantly updated and a backup copy is done based on the date the file is save.

View 9 Replies View Related

Record Filename And Creation Date Of File Used In Another File

Mar 21, 2014

I have a template file that I import data in to, which is then saved with the current date. This works, but I want to automate the import of the data, but ensure I don't duplicate the load.
Therefore, I have a tab 'FileLog' that I record the filename (variable by date) in column A and Creation timestamp in column B.

How do I obtain the filename and creation timestamp of the import data so that they can be entered?

View 11 Replies View Related

Saving A File Without Saving Macro

Jan 30, 2003

I have a spreadsheet that imports data, manipulates it then deletes 2 of the sheets then saves the file under a different name to the network. Is there any way to save this new worksheet without it storing the macros - so when the user open it, only the data is there and they get no prompt to enable macros?

View 6 Replies View Related

Saving Cell Contents To XML File Saved As Current Workbook File Name

Dec 12, 2012

I have numerous spreadsheets that I need to open and unhide a sheet, that has XML data stored in cell A1. What I need to do is copy that data in cell A1 and paste it into a text document and save that as an XML file saved as the XLS workbook name with a date stamp.

I'm running into many issues, the main issue is the saving as current file name, and the formatting of the text/XML file.

Here is my current code, which doesn't reference the current file name and is just very generic. Once I get the saving as file-name correct and the formatting of the xml file correct, I will work on it a bit more.

Code:
Sub Test()
Dim Rng As Range
Dim wb As Workbook
Set Rng = Range("A1:A2")
Set wb = Workbooks.Add
With wb
Rng.Copy

[code]....

View 4 Replies View Related

Filename Inludes " " Around Name When Saving

Jul 25, 2009

I am saving a .csv to a .xls and regardless of what method I use to save it in a macro there are quote marks around the filename in the dialog box. This only appears to happen if I start with a .csv as I have tested it with a .xls and there is no issue. I have tried using the following code so far.

View 4 Replies View Related

VBA For Bypassing Replace File Prompt When Saving As A File In Macro

Jul 7, 2008

I am setting up a "save as" macro that saves a file by replacing another file in a folder. Even though the macro has been recorded by approving the replacement (the prompt appears "the file --- already exists. Do you want to replace the existing file?"), when I run the macro, I am again prompted about replacing the file. Is it possible to avoid the prompt so the file is automatically saved by replacing the named file?

View 9 Replies View Related

Saving Multiple Workbooks At One Time/file As A Text File

Mar 16, 2007

found the following code which works for 1 workbook at a time. I am trying to save 7 workbooks at 1 time. Is it possible?

Sub SaveAsCell()
Dim strName As String

On Error Goto InvalidName
strName = Sheet1. Range("V77")
ActiveWorkbook.SaveAs strName

It will work on the first sheet but none after that. I need to have each workbook saved with the value in cell V77. Also if that is possible, is it possible to change where the file is saved as well?

Right now I have a master workbook that will open the 7 other workbooks, paste data onto several pages in each workbook. I would like the macro to save the workbooks. The workbooks are named: 02 Tuesday, 03 Wednesday, 04 Thursday, 05 Friday, 06 Saturday, 07 Sunday, 08 Monday.

View 9 Replies View Related

Open File With Date In Filename

Aug 6, 2013

I have a csv file named "BB31_2013-08-01". I would like to open this file via vba and this is not my only file. I also have another similar fileames such as "BB31_2013-08-08", therefore, I try to create some function like yyyy, mm & dd where I can modifie it easily for next file.

Here is my code:

VB:
'change weekly
yyyy = "2013"
mm = "08"
dd = "01"

Workbooks.Open Filename:= _
"C:Documents and Settings1314228DesktopTest ProgressBB31& yyyy &-& mm &-& dd.csv"

[Code] .....

View 3 Replies View Related

Copy A File By Specifying A Partial Filename

Oct 7, 2008

I'm attempting to copy some files into an archive folder in the same main folder. These files appear weekly in a folder that contains numerous other files.

Each of these files has a filename such as:

RAH_MRL_TOP_40_(ddmmyy_TIME)

with time being the time that the report was run.

Every week the filename stays the same but the time and date changes. I was hoping to be able to simply use the "Filecopy" command and specify the source file with a "*" after the main file name. However this does not seem to work.

Is there a simple way to do this? (I dont want more than a few lines of coding really as I will be duplicating it for each file and then changing the file name as needed.

View 9 Replies View Related

Corrupt File: Filename.xls Cannot Be Opened

Apr 18, 2006

I was working on a tax file yesturday, just a long long list of receipts. and the file is password protected. However, I went to open it today, and I get a message that says: "Filename.xls cannot be opened. the file may be read only, or you may be trying to access a read only location. Or, the server the file is located on may not be responding."

It's on my USB Drive. I've tried copying it to my HD so I can play with a copy, but no dice. When I try that, I get another error message, : Cannot copy Filename.xls. The file or directory is corrupted and unreadable. I've tried the various fixed suggested in the excel help files to no avail. I did a search on the forum, but didn't find anything that seemed to apply or help me. The computer I'm trying to open it on has Office 2003, the one I most recently worked on the file on has office XP. Not sure if this was a source of the problem. Doesn't seem like it should be. Hasn't been in the past. I'm not even getting to the dialogue box asking for my password yet.

View 2 Replies View Related

Dim A Filename: Pass The Name Of File To A Dimmed Value

Apr 17, 2007

I have a file (I'll call it 'Template' where I am extracting data into a new workbook. I refer back to my Template in my code, but I have now come across an issue. I will save the template using different country names, for example, if I am populating it with UK data, I will call it 'Template - UK'. In my code, how do I pass the name of this file to a dimmed value. So If i have the template - Uk open, can I pass the filename onto a dimmed value? So instead of having

Windows("template - UK").Activate

I want to have something along the lines of (although I tried this way but it didn't work):

Dim template As String
template = Application. ActiveWorkbook
Windows(template).Activate

View 8 Replies View Related

Saving A File With Specific File Name Using Macro

Feb 18, 2009

I am trying to save my workbook in a specific directory with a specific filename and to incorporate a date field from within the spreadsheet. I have changed the format of the cell so it does not include / as i know this would not work. Saving it is the easy part but adding in the field from the spreadsheet is where im falling over.

View 2 Replies View Related

Prompt User For Directory And Filename; Then Save File In Directory With File Name

Jun 10, 2009

I am trying to prompt the user for the directory to be saved in and file name to be saved as; then save the workbook in the input directory with the inputted file name.

View 3 Replies View Related

VB Code To Capture Pathname And Filename

Nov 9, 2011

I want to have a macro (because i do so often) that for any active workbook that I'm using will....

capture the full pathname and file name and place into clipboard for pasting elsewhere.

eg run macro and the following is added to clipboard.....C:Test DirectoryTest_File.xls

View 7 Replies View Related

File Save As With Added Date To Filename?

Aug 9, 2012

I want to create a macro that when executed changes the name of "File1" to "File1 - Edited 8-9-2012". With the date being today's date (variable). This file is going to be emailed to someone who will then execute this macro.

Is there a way to prompt the Save As window with the updated file name so the user can save the file where ever he/she wants?

View 9 Replies View Related

Opening File Paths Where Filename Will Vary

Feb 4, 2014

I'm trying to write code that will open files within a specific folder. However, the end of each filename is going to vary over time to the point that I'll never be able to predict the exact filename.

Is it possible to write something like:

Code:
Set wb = Workbooks.Open "C:\folderfile_filenumberxxxx.xlsx"

Where the "xxxx" signifies the variable element of the file name that could be any four characters? Failing that, is there a similar possible alternative?

View 1 Replies View Related

Search For File With Wildcards And Partial Filename

Nov 21, 2008

I am trying to set a file name as a string to use it as an attachment. The user inputs a number into a textbox. That number is used to locate the file in location. But the file name is different with each file. So im trying to do something like

"C:Desktop*TextBox1*.docx"

Whereas the actual file name is "C:DesktopMCJC RFI 1 MISSING ROOM NUMBERS.docx"

The location "C:Desktop" will always remain the same as will ".docx". I have everything else working just fine.

View 8 Replies View Related

Open File With Changing Filename-2007

Aug 1, 2008

I would like to create a macro to open a file in Excel 2007. My problem is that the filename changes often. After updates are made the filename is changed and the old file is moved to a backup folder. So, there is only one similar file in the folder

My filename is "RFQ Worksheet 7 29 2008.xlsx".
The path is "C:Documents and SettingsahaynijDesktop".

View 5 Replies View Related

Vba Code Which Saves A Workbook With A Variable As The Filename

Jun 25, 2007

I have a VBA form that the user enters information into and once they click submit on the form the code opens a new workbook and then enters the information from the form into that workbook. What I need is for that code to then save the workbook with a filename from one of the fields entered into the form but I'm not too sure how to do this.

View 3 Replies View Related







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