Go Back   Trackpads Community > General Discussions > Computer and Technology > Microsoft Applications

Microsoft Applications Discussions about Windows and other MS Products such as Office

Reply
 
LinkBack Thread Tools
Old 01-23-2005, 16:00   #1 (permalink)
davegb
Civilians

 
Default macro to move from directory to directory

I am writing/recording a macro to make changes in 64 different
spreadsheets in 64 different folders on a network. I am just learning
vba. I don't know how to tell Excel to move through the 64 folders,
test for the spreadsheet to be sure it's there, then make changes. Any
suggestions?
TIA
Dave

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Trackpads Information
Click to Visit
Old 01-23-2005, 16:00   #2 (permalink)
Dave Peterson
Civilians

 
Default Re: macro to move from directory to directory

I would use a worksheet to help out.

In A2:A65, I'd put the 64 folders to check.
In B1, I'd put the filename to look for.

Then something like this:


Option Explicit
Sub testme2()

Dim myRng As Range
Dim myCell As Range
Dim myFileName As String
Dim TestStr As String
Dim tempWkbk As Workbook

With Worksheets("sheet1")
Set myRng = .Range("a2:A65")
For Each myCell In myRng.Cells
myFileName = myCell.Value
If Right(myFileName, 1) <> "\" Then
myFileName = myFileName & "\"
End If
myFileName = myFileName & .Range("b1").Value

TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
On Error GoTo 0

If TestStr = "" Then
myCell.Offset(0, 2).Value = "Missing!"
Else
myCell.Offset(0, 2).ClearContents
Set tempWkbk = Workbooks.Open(Filename:=myFileName)
'do your work
tempWkbk.Close savechanges:=True
End If
Next myCell
End With
End Sub


davegb wrote:
>
> I am writing/recording a macro to make changes in 64 different
> spreadsheets in 64 different folders on a network. I am just learning
> vba. I don't know how to tell Excel to move through the 64 folders,
> test for the spreadsheet to be sure it's there, then make changes. Any
> suggestions?
> TIA
> Dave


--

Dave Peterson
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-25-2005, 12:00   #3 (permalink)
davegb
Civilians

 
Default Re: macro to move from directory to directory

Dave,
Thanks for all your help. I've copied the code for future use. The
macro approach was getting increasing complex as my client kept adding
things they wanted changed in these spreadsheets. I finally realized it
was easier to create a "base" file (like a template, sort of) and just
to a save as to each folder and then change a few text entrys.

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2005, 20:00   #4 (permalink)
davegb
Civilians

 
Default Re: macro to move from directory to directory

I've now created this macro and done some test runs. I can't get it to
find the files in the folders. I'm not even sure it's finding the
folders. It just places "Missing" in column c. How do I tell it where
the folders are? I did change the default location to save Excel files
into the first of the directoriew to see if I could get it to find
them. But I'd rather do it with a macro command than change the default
where Excel files are saved.
When I step through the macro, I get a message that "C:\" cannot be
found. So I'm guessing that the macro is looking in the root directory
rather than where the files are stored.
Any ideas?
TIA

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2005, 20:00   #5 (permalink)
Dave Peterson
Civilians

 
Default Re: macro to move from directory to directory

The first code looked for the folder names in column A and the workbook names in
column B.

But read my follow up post if the names of the workbooks varied.

davegb wrote:
>
> I've now created this macro and done some test runs. I can't get it to
> find the files in the folders. I'm not even sure it's finding the
> folders. It just places "Missing" in column c. How do I tell it where
> the folders are? I did change the default location to save Excel files
> into the first of the directoriew to see if I could get it to find
> them. But I'd rather do it with a macro command than change the default
> where Excel files are saved.
> When I step through the macro, I get a message that "C:\" cannot be
> found. So I'm guessing that the macro is looking in the root directory
> rather than where the files are stored.
> Any ideas?
> TIA


--

Dave Peterson
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2005, 20:00   #6 (permalink)
davegb
Civilians

 
Default Re: macro to move from directory to directory

Thanks for your prompt reply!
In the test I did, all the filenames were the same. I decided to do it
that way at first, then add the complication later. So this was run
with all the file names the same. The workbook name was in B1.

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2005, 20:00   #7 (permalink)
Dave Peterson
Civilians

 
Default Re: macro to move from directory to directory

You put the common filename in B1.

You put the folders in A2:A65?

I'm guessing that the folder names weren't spelled correctly. Or since all were
marked missing, maybe the filename wasn't spelled correctly. (Did you include
the .xls?)



davegb wrote:
>
> Thanks for your prompt reply!
> In the test I did, all the filenames were the same. I decided to do it
> that way at first, then add the complication later. So this was run
> with all the file names the same. The workbook name was in B1.


--

Dave Peterson
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
New link directory Richard Web Design 3 10-17-2005 10:05
Macro to load photo from a directory into powerpiont slide Blaine76 Microsoft Applications 8 06-03-2005 12:00
Directory Assistance Snowden Humor 2 03-21-2005 09:43
The War Veterans Directory Otis Willie Hobbies 0 01-06-2005 01:00
Setting directory for file save in macro Jake Microsoft Applications 7 06-15-2004 17:19


Community Information
Options
Quick Options
Trackpads Non-Commercial Ad
Copyright Information Click to Visit
Time
Server Time
All times are GMT -4. The time now is 13:18.
Copyright
Copyright Information
The header is based off of work by Vipixel.com and modified by this site. Trackpads and the Trackpads Logo are both Registered Trademarks of Jason Edwards and cannot be used without prior written permission.  The only exception is as a link back to this site. Trackpads is a private website run by a small legion of volunteers, 3 dogs, 12.5 cats and an army of small, super smart, bio-engineered mice with pointy hats and tutu's. Search Engine Friendly URLs by vBSEO 3.2.0 RC7
Archive Links
Archive Links
Page generated in 1.75581 seconds with 19 queries