Saving To/creating Folders In VBA

Jun 3, 2006

I'm trying to save a spreadsheet using VBA which will also check that the directory exists and create it if not, all based on cell values in my spreadsheet. When I run my code it comes up with Run Time Error 76: Path not found.

Dim fname As String, dname As String, dname2 As String
fname = ActiveSheet.Range("E2").Value
dname = ActiveSheet.Range("G2").Value
dname2 = ActiveSheet.Range("H2").Value
Windows("Register Template.xls").Activate
ChDir ("H:")
If Len(Dir(dname2, vbDirectory)) = 0 Then
MkDir dname2
End If
ChDir dname2
ActiveWorkbook.SaveAs Filename:=fname

View 4 Replies


ADVERTISEMENT

VBA Saving PDF Files Into Folders

Sep 29, 2013

I have this code that generates excel pages as pdf files, but I can't get it to save it in its individual folders. For example, I have the sheet name as Brian Lin, I want to save the pdf into the folder called Brian Lin, then if I have the sheet name as Lilly Tran, the pdf should save into the folder called Lilly Tran. Here's my code. The code is one step short of what I want it to do, it saves in the folder right before the name folders.

Code:

Sub Macro1()
Dim wsh As Worksheet, vWshs
Dim sFolderName As String, set_Path As String, name As String, hwas As String, sname As String, swsname As String
vWshs = Array("Rates", "Inputs")
set_Path = "C:UsersJonathanDesktopFaFundInvoices" & hwas & ""

[Code]...

View 4 Replies View Related

Saving Reports Into Different Folders With Different Logos And Title

Nov 21, 2012

I have 40+ reports that I generate weekly for different clients.

I have the workbook set up so that each report is in a new sheet/tab and have a macro that runs through and saves each report as a PDF using the file name I desigate in a cell within the sheet.

My clients are now wanting the reports individualy branded to them.

My thinking is that I can list each clients name, phone, website, etc. in a new sheet then develope a marco that runs through and save the reports with row 2's infomation filled in on the reports, then row 3's and so on but one I don't know how to create a marco to do that and two they also want their logos on the reports.

Can I place an image in a cell and have it called into another cell? Can I place them all in a folder and have it call the image in based on the location and name?

View 1 Replies View Related

Saving Sheets In New File In Different Folders Depending On Cell Value

Nov 13, 2012

I'm actually using a macro that saves all the sheets from a workbook in new separate files, and save them in a specified folder.

Code:
Sub Estrazione_Schede()
Dim n As Long
Dim myNome As String
Dim myPath As String
myPath = "D:path"

[Code] ......

What I'm trying to do is that, instead of saving all the sheets in one folder, the macro would save them in different folders, depending on specific values in a specific cell of each sheet. I tried to modify the macro like this, but it doesn't seem to work properly:

Code:
Dim n As Long
Dim myNome As String
Dim myPathOne As String
Dim myPathTwo As String
myPathOne = "D:pathOne"

[Code] .....

With this code the macro ends up to check the condition only in the first sheet and then it copies all the sheet in the same folder.

View 2 Replies View Related

Creating Folders From Spreadsheet?

Jan 3, 2009

I need some help, I know very little about macros but is it possible to create folders/directories to a certain path using the text in an excel spreadsheet cell? For example, if cell a2 has a street address and cell b2 has a city, can it automatically create a directory in the path of my choice using that data? If yes, can it go down the the rows and create directories until it is done?

Please help as I have hundreds of directories to create.

View 6 Replies View Related

Creating A Series Of Folders Named From A List

Feb 25, 2010

I would like to create a series of folders in explorer using a range of cells A1:A162 for the names of the folders. Wondering if there is a way that I can automate this using VBA versus doing it manually .

View 9 Replies View Related

Creating Folders On Shared Drive - Path File Too Long

Dec 5, 2011

I've made a macro that would create some folders on a shared drive.

there is an issue if the path i want to create is too long.

I get this error.

Uploaded with ImageShack.us

is there anything we can do to pass this or any solution for it?

View 5 Replies View Related

VBA - Creating And Saving New Workbook

Oct 26, 2011

Ok, I'm trying to learn how to create and save a new workbook using VBA...having some issues with this error:

Run-time error '1004':

Method 'SaveAs' of object '_Workbook' failed.

The line is highlighted in red.

Code:
Sub Copy_ActiveSheet_1()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String

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

View 7 Replies View Related

Saving Groupings When Creating New Pivots?

Sep 28, 2011

I have a monthly sales report with x amount of customers in a number of countries with an ABCDE mark. I have made a pivot table with ABCDE marks in rows and countries in Columns.

I have then grouped the countries into regions. Looks something like this: [URL]

If you can't see it look here: [URL]

Now my issue is that I have to compare many months of this kind of data to see movement. What I wanted to do was to display these changes but how do I do this without having to create 10 different pivot tables, and is there a way I can save the country groupings so I don't have to manually group the countries for every pivot table?

View 1 Replies View Related

Use Excel VBA To Copy Multiple Files From Different Source Folders To Different Folders?

Jun 12, 2014

I need to back up files, which may be excel or MSword, by copying them from different directories, say C: to the backup directory, say X:. any vba to backup the files? I expect the vba can copy all file listed in column A.

E.g. C: est1File1.xls or C: est2File2.doc, and then pasted to the directory in column B. e.g. X:BackupFolder1 or X:BackupFolder2.

View 1 Replies View Related

Arrange Or Group Folders Based On Assigned Icons To Folders Using VBA

Dec 20, 2011

I have folders with different assigned folder icons based on the content in the folders.

I would like to arrange these folders in the window based on the assigned folder icons and then by alphabetical order.

How it is to be done. Can we make use of vba having the folders path list in one column of excel sheet?

View 9 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

Search Folders And Sub Folders For Worksheet And Return Range?

Jul 8, 2013

macro and I think this has me on my way; however, I do not understand the code and I am having difficulty modifying it. It returns the path in cell $A1 of my workbook, but I get reference errors in $B1:$L1.

I would like for the code to start entering the values in row 2 of my current worksheet. Row 1 I want to make a header row. The first column I like having the file path. Can the path be changed to a hyperlink? I would then like for it to return the values in $AP1:$BC1 to $B1:$O1 of my current workbook.

View 4 Replies View Related

Making Macro That Will Create New Folders And Then Save In Those Folders?

May 21, 2014

I am attempting to create a macro that will create a new folder on the network drive Arie:quotes that will create the new folder and save the the file in the new folder. I need the name of the file and folder to be set to the master (worksheet) cell "B3". and then if possible have it be conditional that if cell "B40" on the same master (worksheet) has a value to have the value added at the end of the filename via hyphen. This workbook has numerous worksheets in it approx 15 worksheets. I am not sure if this is relevant.

As an brief example.

Cell "B3" on the master(worksheet) contains a job name I-40 bridge
So initially I would like the Folder name and file name to be I-40 Bridge

However once the Cell "B40" has been filled in with the value 54213 then I would like the file to renamed to I-40 Bridge-54213 and saved within the same folder.

I am currently working with Excel 2007 Pro edition on windows 8. I

I have found several other macro's that work with an auto save but i am unsure of how to change the directory to the network drive and show the correct file paths. This is the example of the macro I am currently working with.

Public Sub SaveAsA1()
ThisFile = Range("B3").ValueMkDir "C:NewFolder"ChDir "C:NewFolder"ActiveWorkbook.SaveAs Filename:=ThisFileEnd Sub

View 4 Replies View Related

Consolidate Data From Multiple Files Within Folders & Sub Folders

Aug 16, 2009

I have managed to get this far - I have put together a macro (from different threads on this site) that opens closed workbooks, copies data in one of the sheets (same sheet in each of 28 books), and pastes the data it into a master book sheet, each paste starting below the last. So that bit is working. The first bit of help I need is a line of code that will make the macro loop through a number of sub folders in a main folder. My code at the moment works as long as I specify a path that ends with the name of one subfolder, and it only loops through this subfolder. I would like the path to end at the folder that holds all the subfolders ('Workbooks' in the path below), and then add some code that tells it to apply the macro to all subfolders in this folder, so it loops through them all.

The second issue is that after the macro goes to the closed book(s), copies the data in there and pastes it into the master sheet (into columns E:FG), I then need it to go back to the workbook it just copied from, go the same sheet, to three specific cells on that sheet (FH1:FH3), copy the content, go back to the master sheet, and now repeatedly paste the content (values only and transposed) of these three cells into three cells (in columns B:D, with row number being dependent on what rows the first lot of data was copied into) next to every row it just previously pasted in for me. When it loops to the next workbook, it needs to do the same, and the three cells will have different content than the ones in the previous workbook paste.

I dont know how to define the range it needs to paste into the second time. I tried using the definition I used for the first paste (MCDrow), to tell it that it is the same rows, just different columns, but this is not working.

Here is what I have so far, which does the first part of what I need, except for needing a way to have it loop through all subfolder in the 'Workbooks' folder (at the moment it lists Barwon South West as a subfolder in that path, but I actually have multiple subfolders, not all called Barwon South (all different names) that it needs to loop through and do both the first and the second paste for. I have taken out the code I was trying to use to do the second paste, as this was not working and the code is pretty messy as it is (I sort of bumble along, being so new, and I know the code is not very clean or efficient!).

Can someone help me put in the few lines I need to loop through all my subfolders (if you give me an example I can probably extrapolate), but to get you started, three of the subfolders are Barwon South West, Eastern Region and Gippsland. And can someone help me put in the code that will do the second paste for each workbook?

Sub Click2()

Application. ScreenUpdating = True
Dim MCDrow As Long
'Dim SubFolders As String
MCDrow = ThisWorkbook.Sheets("Client Data").Range("A65536").End(xlUp).Row

Fpath = "Q:Clinical ServicesCS Statewide DatabaseWorkbooksBarwon South West" ' change to your directory
'SubFolders = True
Fname = Dir(Fpath & "*.xls")
Do While Fname <> ""

ThisWorkbook.Sheets("Client Data").Unprotect

Workbooks.Open Fpath & Fname
Worksheets("Client Data").Activate
Worksheets("Client Data").Unprotect

View 6 Replies View Related

Excel 2010 :: Creating Mandatory Field Before Saving A File?

Aug 22, 2013

coding mandatory field in Excel 2010.

This is a code that i have for having a master workbook, and saving it in different folder so my employee cant access it

Sub NextInvoice()
Range("J2").Value = Range("J2").Value + 1
Range("E6:E9,H9,J9,B14:K20,H4,B28:K32,B36:B39,D36:D39,F36:F39,B42:K43,B46:K47,B50:K51,B54:K55,B58:K59,B62:K63,B66:K67,B70:K71,B 74:K75,D78:E78").ClearContents
End Sub
Sub SaveInvWithNewName()
Dim NewFN As Variant
'Copy Invoice to a new workbook

[code].....

I have found a code for mandatory cell, but it creates a second macro and i was not able to link the two.The mandatory field has drop down of employee's and it is located in the cells D78:E78.

View 1 Replies View Related

Loop Through Folders And Create Folders?

Mar 31, 2014

I want to open C:Projects

and for each Project in Projects, create a new folder with the actual month (e.g. "03" or "12")

Im running the Makro from a file where I'd like to put the month in a cell -> so the code refers to cell("A1") wich has value 01 and creates a folder "01" in every projectfolder in C:Projects

View 3 Replies View Related

Creating New Workbook / Copying Sheets And Saving Workbook - Subscript Error

May 30, 2014

Trying to create a new workbook from another open workbook, then copying all the sheets that aren't called "Summary" to that new open workbook and then saving it. I get a subscript error on this line:

[Code]....

View 3 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 User Inputted Data From A Worksheet To Another Worksheet And Saving It

Jan 7, 2009

I have created a form in a worksheet which I have added questions too and then locked all cells except the ones where I want the answers in.

I have then added a button to the bottom of the sheet called "Print and Save". This work sheet is called "form"

On a second sheet called "database", I have all the titles of the questions running from a -> k and nother else.

What I want to happen is the user input the information on "form" into the boxes available. Once they have completed the questions, I want them to be able to click on "Print and Save" so that firstly the page "form" prints, and then for all of the answers to be saved in "database" below the titles for each question.

I have had a play, but just don't know where to start. Also, once there is a row of questions below the titles, I don't want it to overwrite information already there, it needs to go onto the next empty row available.

Attached is my excel file.

You will see in the code that I have the code for printing.. I just found this on the net and it seems to work fine for me.

View 9 Replies View Related

Opening All Folders

Jun 20, 2008

I have about 20 plus workbooks in a folder. Each has 52 sheets, Fridays date, that I want to copy all the data from each sheet.

Is there a way to open all workbooks in a folder and copy all data from on all the various sheets into a single workbook?

I'm trying to gather the info and make a small data base from the various books. I'd like not to have to call each workbook by name as the file names change or get added to.

View 11 Replies View Related

Listing Folders With VBA

Oct 10, 2008

I have found a lot of posts which show me how to list a directory tree in an Excel file, usually using a macro. I'm just uninitiated with VBA / VBS and simply don't have the time to figure it out now (it really isn't part of my job description... I'm rather doing a favor here).

I need to be able to re-generate an excel-based list of clients at will. The client names are subdirectories of different case types. There aren't tons of case types, right now maybe 20 but I need to be able to add case types without breaking the script.

case_typeslast,_first_name........

View 5 Replies View Related

Run Macro In Sub-folders

Dec 25, 2010

I have created a macro named "SummaryCalculation" and I want to run this macro to more than 100 excel files which are saved in subfolders in a main folder. Each subfolders have atleast one excel file. I want the macro to be run with in these subfolders not the files are in main folder.

View 3 Replies View Related

Files Within Sub Folders

May 29, 2007

I am using the code below to list all files within a specific folder however I need to know about ALL the files within the underlying sub folders (of which there are many).

I have tried wildcards when declaring the folder but it does not work.

Sub List_Files()

Dim fsoObj As Object 'Scripting.FileSystemObject
Dim fsoMapp As Object 'Scripting.Folder
Dim fsoFil As Object 'Scripting.File
Dim sFolder As String
Dim i As Long
Dim filtype As String
sFolder = "V:T-ASSETAsset ScotlandNetwork Capacity Section1 Business Plan"

Set fsoObj = CreateObject("Scripting.FileSystemObject")

'Set fsoObj = New Scripting.FileSystemObject........................

View 9 Replies View Related

Create Folders VBA

Dec 6, 2007

I m having difficulty combining code to do this; create folder in network drive from excel list

T:Bob
Then subfolder T:BobFinancials
Then subfolder T:BobSecurity

View 3 Replies View Related

List Folders To File

Aug 11, 2005

Does anyone have a macro that would list all the folders (with path) and
subfolders to an excel sheet but not the files?

View 14 Replies View Related

Select Folders In Excel Vba

Jun 26, 2014

I want to open 2 or more folders in excel vba how its possible.

View 4 Replies View Related

Open Workbooks In Two Folders

Jun 24, 2009

I have a script below that opens all the workbooks in a folder based on a msgbox. The script works as is. However what I would like to do is remove the msgbox and have the script go back and forth between the folders.

Example it would open one workbook in the (Large Area)folder call my other script (Hazleton_Data_Conversion) Return Open a workbook in (Varsity) Folder Call the
my (Hazleton_Data_Conversion)and repeat the process till all the workbooks in both folders have been processed.

Like I said this script works with the msgbox I just like to change to without msgbox and to flip back and forth.

View 3 Replies View Related

Multi-Level Folders In VBA?

Apr 19, 2012

I have the following function. the problem with this excel is i give it "C:" as directory, it search only one level of sub folders i.e it will search the filename in

C: est
C: est3

It does not go deeper. i.e it wont look in folder that is for example

C: estanotherlevel
C: est3anotherlevelmylevel3

How to modify my function so that it goes to the deepest folder. is there a way to do it?

Function GetFile(directory As String, filename As String)
Dim FSO As Object
Dim fldr As Object
Dim subfldr As Object
Dim file As Object
Dim fullname As String

[code].....

View 2 Replies View Related

Deleting Folders Within A Macro?

Aug 23, 2012

So I have a macro that creates a monthly set of reports, but some of them only relate to period 5 onwards. I wanted the macro to check whether a folder exists for periods 1 to 4, and if so, delete the folder and all the files inside it. I've used the following...

Code:
If Period < 5 Then
If Dir("I:AcctsCentral EngineeringEngineering Reporting Pack2012-131 April 20122-2 Reports - 4+8 Reforecast") "" Then Kill "I:AcctsCentral EngineeringEngineering Reporting Pack2012-131 April 20122-2 Reports - 4+8 Reforecast[code]....

but the macro just skips straight through the secondary IF statements without stopping.

I know this works on deleting files, and presumed it did too for folders, but it doesn;t.

View 2 Replies View Related







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