Save Macro - Create Folder If It Does Not Already Exist?
Sep 11, 2012
I have the following code which saves a certain sheet to a new workbook and then emails it to a range of cells. The directory the file is saved in is from a cell, and changes depending on certain cells in the workbook. I would like to make it so if the folder it is saving to does not exist, it will create it. If this isn't possible with this set up, I would just like it to display an error message if the folder is not present.
VB:
Sub Save_Report()
Dim wbName As String
Sheets("TELELINK & ITINERARY FORM").Copy
[Code].....
View 1 Replies
ADVERTISEMENT
May 27, 2009
I want to create a macro that will create a new folder called "Fungicide Quotes" under my documents and will save the workbook using the cell reference d4:f4 for the file name, which are merged cells. I have tried the following but can't get it to work. Any help would be appreciated, Thanks
Sub Save_wrkbk()
Dim strFilename, strDirname, strPathname, strDefpath As String
On Error Resume Next
strDirname = "Fungicide Quotes"
strFilename = Range("d4:f4").Value
strDefpath = "C:My Documents"
If IsEmpty(Filename) Then Exit Sub
MkDir strDefpath & strDirname
strPathname = strDefpath & strDirname & "" & strFilename.......................
View 9 Replies
View Related
Nov 25, 2009
I currently use the following code to create a duplicate file based on two cells within a directory and folder i specify. These cells consist of the team and week commencing date (mondays date of week which is cell 'Main Menu'!K8)
View 7 Replies
View Related
Jul 6, 2013
I'm having a little trouble making this code work correctly. This macro, Once finished, is connected to a (Save) command button. Here is what is suppose to happen, First thing to remember is another sheet (Sheet1) has been populated with various information which is used as a receipt. The information came from sheet2. I need to copy sheet1 just as it is, format included, create a new empty sheet, paste the information into the new sheet, name the new sheet with the values from cells in sheet2, E3, D3, and the date formatted as the month and year only. Then I need to create a folder in the my documents folder named from the values from sheet2, E3, D3, and todays date with the current time. If the folder already exists, then I just need it to change to that folder, and save the newly created worksheet (as named above) into that folder. After the save is executed, I need to delete that new sheet from the current workbook. Then I need to return to sheet2 to the last active cell and run the last few lines of code which collects the value of the cell 1 to the right of the active cell and transfers it to the cell 1 to the left of the active cell.
VB:
Public Sub Button11_Click()
Dim wShell, fso, strFldr, xdir As String
Dim newbal As String
[Code].....
View 9 Replies
View Related
Apr 27, 2013
I want to write a piece of code where each day i run this code
I want add a workbook
Copy range ("A1:C5") to this new workbook
Save new workbook in a particular folder with the name customer data and todays date and save as CSV file
I run this this code every day so it should only add todays date at the end for filename
If for some reason I run this code again in the same day..
I want to have a msgbox stTing you have already ran this code today and exit sub
View 4 Replies
View Related
Jun 14, 2009
In Cell N1 i have 02/02/09 but i have formatted it to look like Feb Invoices 2009. In the strpath below it saves the file to a folder In desktop/"Cell N1" But it tries to save it as c:Documents and SettingsDaveDesktop229 I would like it to save as c:Documents and SettingsDaveDesktopFeb Invoices 2009. Also if the folder does not exist the macro fails. How can change this macro to
1. Change the folder from 020209 to Feb Invoices 2009
2. If folder does not exist then create it.
View 2 Replies
View Related
Apr 13, 2009
looking for some code to save to a destination
destination address is
C:Documents and SettingsstDesktopOJF
now the problem is OJF has folders named 1 to 500
so if cell d5 = 487 it will need to look in the above desination and then open the folder and save it there.
View 10 Replies
View Related
Feb 2, 2014
I have the below code that saves selected sheets of my workbook as pdfs in the current file location. What I would like this code to be able to do is to create a new folder (named with todays date), and then save each of the pdfs into this folder.
Code:
Sub SaveWorksheetsAsPDFs()
Dim sFile As String
Dim sPath As String
Dim fPath As String
Dim wks As Worksheet
[Code] ........
View 3 Replies
View Related
Oct 23, 2007
I have a workbook which consists of 28 worksheets, all of which are protected, and are running on a code which automatically keeps all sheets at "unlocked cells" in the selection field. The sheet is also password protected for write-access…
I would like a Macro, or some sort of code, that when activated… it unprotects ALL sheets (which use same password), creates a folder on the users desktop, and saves a copy of the document in there… entitled "copy of {filename}" It must also remove the "write access" password…
View 9 Replies
View Related
Dec 19, 2008
i want to create folder depending on cell value a1 select data from a1 to h20 save this as "b1 value.xls" my saving directory is c:
eports"a1value" ....
View 9 Replies
View Related
Jan 17, 2010
I have a macro that copy one sheet of the Active workbook and sends it via email.
I need to add a code in this sheet so when one opens it from the email, with a command button to be able to save the file to specific, fixed folder on the local network with it’s original file name.
View 10 Replies
View Related
Apr 29, 2014
Looking for VBA code to automatically save an excel file as an .xlsx format, and saving to a specific folder: C:UserswolfmDesktopLoad Lists
I have been using the attached code, but it's not working. It saves to the desktop, not the folder. Also, when it creates the file name based on sFile = ActiveSheet.Range("C4").Value & ".xlsx", it adds wierd things to the file name. I want the file name to be simply the value in C4.
View 2 Replies
View Related
Oct 8, 2008
I have a macro that currently saves and prints the sheet I'm working on. At the moment, it saves everything in the same place and always calls the file the same name.
In the worksheet, a lookup does actually specify what folder it should be saved in and what name it should be given. How can I write the code so that it pulls up the name and the folder directly from the sheet it's saving?
View 3 Replies
View Related
Sep 17, 2009
Our small company only has 5 computers in it with mine acting as the "server". I want to put a macro on our customer order forms that all computers can access on the server that will save the file as 3 or 4 cell names serparated by commas and save it in a specific location on the server.
I got the macro to work perfectly on my computer but when I try to type in the appropriate path to the server the file gets saved in their My Documents folder 99% of the time. I did get it to work twice but it seembed to be completely random as it didn't work any of the times before or after.
Here's what I have so far: ...
View 9 Replies
View Related
Dec 7, 2012
I have a folder called "Report" at C: and inside this folder there are 12 folder named from 1 to 12 ("1","2",...,"12")
I need a macro to save my workbook as a file in C:Report(one of these folders depending on the month of a certain cell)
i.e. if the date in this cell is 8/12/2012 .. then save my file in C:Report12*.xlsm
This is the code i use
Code:
Private Sub CommandButton1_Click()
Dim fname As String
fname = Format$(Range("S8"), "dd-mm-yyyy")
On Error Resume Next
ActiveWorkbook.SaveAs Filename:="C:Reort" & fname & ".xlsm"
End Sub
So what i need now is what to insert after C:Report
View 9 Replies
View Related
Mar 27, 2014
how to save multiple file with other names in the same folder
View 1 Replies
View Related
May 6, 2014
I have this existing macro which saves each tab into a separate excel file. However, I'd like for it to also save them together in a new folder using the current month and date (named: QA Files May_05.06.14). The month and date would change according to current month/date. How would I incorporate that into this code? I am not good with macros.
Sub tabname()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
ws.Name = Range("D1").Value
Next
[Code]...
View 4 Replies
View Related
Aug 6, 2008
I have a report send to me daily. And I want to have a macro to save this report in the daily folder, such as “c:
eports8052008”, so tomorrow 's folder would be “c:eports8062008”.
All the daily folders already exist. Just need to change the file path. I tried some codes including sPath and format(now(), “mmddyyyy”), get error message.
View 9 Replies
View Related
Mar 6, 2014
Can a macro create a folder in my computer and use the value in cell A1 as the folder name? This is where I want the folder to be created C:UsersUserDesktop.
View 8 Replies
View Related
May 14, 2014
I have alot of project folders on my harddrive.
All in format: I:/12345-costumer-projectname/
The five digits are unique for each project.
I make calculations for these projects using an excel file. In this excel I also type the projectnumber (cell J2)
Now i would like to make a button. When pressed, it checks the projectnumber cell J2, looksup the corresponding folder and saves the excelfile in PDF format in this folder.
I have found macro to find files in folders, but none which do the above.
View 4 Replies
View Related
Jan 24, 2007
I have a function that works well for checking if a specified file exist within a specified path. I realized I do not know how to just check if the folder exist!
Example: I want to see if the following folder exist with boolean response...
"C:MyCompanyMyDeptMyFolder"
View 9 Replies
View Related
Apr 21, 2014
I have up to 50 workbooks in one folder with data in a specific range. I also have one workbook which includes additional data, including conditional formatting and dropdowns. I need to copy the desired range from the first workbook in the source folder to the second workbook, then save the latter to my destination folder, using the same name as the first. I need to repeat this process for all workbooks in the source folder.
View 2 Replies
View Related
Jul 18, 2014
I have a list of items in an excel sheet... 500 of them... and there are images for them in an other folder... The problem is those images are in 1000's and I only need those 500 images.. Images are saved as "SKU.jpg eg NS2354.jpg and we have an SKU column in excel as well .. SKU and their images have same name...
Is there any solution to pick up only those 500 images from those thousands of images?
Is it possible to save those 500 images in an other folder?
View 2 Replies
View Related
Apr 1, 2014
I am using this code to generate a text to a directory, but I would like to know how to call a save as prompt if the directory doesn't exist?
[Code] ..........
If the folder macro does not exist, then it will prompt a message saying that the folder macro cannot be found, and the save as prompt will appear.
View 3 Replies
View Related
Jul 31, 2009
I have figured out how to save the workbook using a variable to saveas but I would like to create a new folder to place the new workbook into. I have tried a few things a am not having any luck. I recorded a macro and the code it produced is as follows.
View 6 Replies
View Related
Apr 26, 2014
I would like to create a code that will open all workbooks in folder "A" one at a time and then close the work book after another code is executed. So one workbook will open and while the workbook is open, I will call another code to format the active workbook and then the active workbook will be saved in folder "B" and closed and go to the next workbook in folder "A" to start all over. The folders are saved on the desktop.
View 5 Replies
View Related
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
May 22, 2008
I need to create a worksheet and then populate it with header row containing columns names, and with values starting at row2. Before I do all this I wanted to first create a spreadsheet, I was successful in getting this done by getting a piece of code from this website. But, what if spreadsheet already exists from a previous run, then, in that case I want to clear the contents. Before I get too far ahead, I am unable to escape runtime error 9, array subscript out of range whenever I use any sort of code to check if the sheet exists.
Also, my attempts to circumvent this error by putting in errorhandling is ignored, i.e. I get the standard run-time error message box, but, not what I want the code to do is such an error occurs.
Function wsExists(wksName As String) As Boolean
On Error Resume Next
wsExists = CBool(Len(Worksheets(wksName).Name) > 0)End Function
Private Sub Cmbsummary_Click()
On Error Goto ErrHandler:
'Worksheets("MySheet").Activate
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "MySheet"
Exit Sub
View 4 Replies
View Related
Sep 8, 2006
Read “My Documents” Path And Use Result
Problem:
Note:
Typical user OS will be Windows XP Pro / Win 2K
Excel version : 97 / 2002 / 2003
1. Corporate network security settings will only allow directory/subdirectory creation in the “My Documents” section of customers individual computers.
2. Per customer request, VBA application needs to save extracted files for future use.
3. I can specify an initial “My Documents” subdirectory be made and the VBA application file be loaded/copied into that location – i.e. – “My DocumentsCat”.
4. When VBA application is opened from that specified directory, (first time), the application needs to make an additional subdirectory tree to save future files. I can read the opened from location via VBA with the following:
Dim filepath As String
filepath = ThisWorkbook.Path
As an example – this code would produce a string definition of “filepath” – such as the following:............................
View 5 Replies
View Related
Dec 30, 2008
I have an addin in a shared folder which was created by someone else. (it is a user form). I need to create a macro which will go to its existing folder and then save it in the users personal addin folder also picking up their user id. There will be about 100 users so easier this way than going round doing it for them.
So I suppose the query is three fold.
1, pick up the addin and save it in a personal addin folder.
2, Find the username as part of the path file. For instance my personal would be:
"C:Documents and SettingsO033116Application DataMicrosoftAddIns"
The "O033116" is where I will need a search completed to obtain the user id.
The addin is called ServiceCredt.xla
3, Activate the installed addin.
The reason I want it this way is so the user is unable to access any of the code and we are in control.
View 8 Replies
View Related