Rename files and save them as pdf

B

Braca

The main folder, say c:\main contains subfolders c:\main\one, c:\main
\two..., and in each of these subfolders there is one text file named
summary.txt.

The macro needs to:

1. get the summary.txt from each folder
2. rename the file to the name of the subfolder from which it was
opened
3. convert/print renamed file to a pdf file with the same name, e.g
one.pdf, two.pdf...
4. save pdf file to the specified folder, say c:\renamedfiles

Can you please suggest the code?
 
R

Rod Gill

Try recording a macro of you doing this manually. The recorded code will
give you a great head start.
 
B

Braca

Try recording a macro of you doing this manually. The recorded code will
give you a great head start.

Tried it already. Recorded macro will not show me the most important
part - how to extract the name of each subfolder and assign it to the
renamed text file, and how to do all that in a loop until the last
subfolder is reached.
 
G

Guest

Hi,

Suggest you have a look at the "Dir" function in VBA Help. The example lists
all sub-directories in a given directory.

This gives you the loop you want.

Each time through the loop you get the next directory name in MyName, e.g.
"One".
Place your recorded code where the Debug.Print statement is in the example
and
replace the "one.txt" in your recorded macro with MyName & ".txt"

This should answer your questions so far.
 
T

Tom Ogilvy

You know what you want to do better than I, but renaming a file from .txt to
..pdf doesn't make it a pdf file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top