473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VBA to browse for folder of excel files and then save as new file

I need to be able to have a prompt to select the file folder containing excel files, then have the vba open each file and save them in a new folder. Below is the code that is not currently working:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command35_Click()
  2. Dim strFile As String
  3. Dim strPath As String
  4. Dim strBrowseMsg As String
  5.  
  6. strBrowseMsg = "Select the folder that contains the EXCEL files:"
  7. strPath = BrowseFolder(strBrowseMsg)
  8.  
  9. sFile = Dir(strPath & "*")
  10.     Do While strFile <> ""
  11.       Workbooks.Open (strPath & strFile)
  12.       result = ActiveWorkbook.Name
  13.  
  14. ActiveWorkbook.SaveAs _
  15.       FileName:="C:\Users\tdri004\Desktop\KeHe\KPOF\Loaded KPOFs into Database\" + result, _
  16.       FileFormat:=51
  17. ActiveWorkbook.Close True
  18. strFile = Dir()
  19.   Loop
  20.  
  21.  
  22.  
  23. End Sub
Nov 18 '12 #1
2 3222
zmbd
5,501 Expert Mod 4TB
Out of curiosity... why are we duplicating what the OS does quite well?

Do you need a custom dialog or will the windows dialogs work for you?

Also I would use the Name function to rename the files as this makes DOS do the work and not the vba engine.
Nov 19 '12 #2
NeoPa
32,556 Expert Mod 16PB
I'm not sure you're looking to rename (or Move) the files, but even if copying them there is a FileCopy command that would do the job more simply than opening and resaving them.

If you want just the Excel files from the specified folder then change line #9 to specify "*.XLS" or "*.XLSX" (depending on the type of files you're dealing with).

I suggest you look at making those fundamental changes first, then return here with your new code and details of what is not working at that stage. No-one likes questions where the OP simply imparts the fact that something "isn't working". Why ask for help if it's working after all. What makes a question make sense is details of what isn't working and, when code is involved, which line of code is causing the problem if known.
Nov 19 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oci-One Kanubi | last post by:
Everything works fine in Access, but when I double-click on the resultant Excel files the first one opens correctly, but subsequent ones, and any other Excel files I try to open, fail to display at...
3
by: yaya via DotNetMonster.com | last post by:
Hi, I'm using OleDb to read an excel files and display the data in a datagrid (using dataset as data source), after modifying the data on datagird, how can I save the changes back into Excel files. ...
10
by: GJP | last post by:
Hello. Ive been asked to make my own notepade for college assignment. All ig going well, but i cant get the save to work. I can get Save a (shows dialog box), i can get it to just save too,...
0
by: Rich Wallace | last post by:
Hi all, I have a large number of Excel files on my file server that stores schedule data from several different divisions. They use embedded macros inside the worksheets that do some date...
8
by: matt | last post by:
hello, can anyone speak to some of the common or preferred methods for building Excel .XLS files, programmatically thru the .NET framework? i have an intranet app that needs to generate &...
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
2
by: reb0101 | last post by:
hey all, I would very much appreciate any help or ideas on how to do this as I am stumped. I need to develop an access database to track documents but also link to them. I’ll explain what it...
1
by: msanger | last post by:
Hi, I have several excel sheets in Office 2007, which has all kinds of standard calculations, and a consolidated Excel Sheet with totals and rollup of all the other excel files. The issue I am...
1
by: flickimp | last post by:
Hi I have an excel file with 20 sheets. Now then... I am only interested in one Sheet (2 pages) and I want to save that to a particular folder. Also, the sheet is dependent on Cell D7...
1
by: helplakshmi | last post by:
Hi All, I wish you a Happy new year!!!.. My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.