Two more macro questions

G

Guest

Hi everybody,
Thanks for your help so far! I have a couple more macro questions that I
need to get cleared up, though, and I was hoping someone could answer them--

1. Is it possible to write an AutoClose macro so when a document closes, it
saves as a text file of the same name on the D drive?

2. If that macro is possible, is there a way to apply it to all the
documents in a folder without going through each one manually and retyping it?

Thanks!
Jezzica85
 
J

Jezebel

1. Is it possible to write an AutoClose macro so when a document closes,
it
saves as a text file of the same name on the D drive?
Yes




2. If that macro is possible, is there a way to apply it to all the
documents in a folder without going through each one manually and retyping
it?

Yes
 
G

Guest

Thank you Jezebel, but would you mind elaborating on how to apply the macro
to all the documents in a particular folder?
Thanks!
Jezzica85
 
J

Jezebel

Dim pFileName as string
Dim pDoc as word.document
Const pFolder = "C:\.......[whatever]\"
pFileName = Dir(pFolder & "*.doc")
Do while len(pFileName) > 0
set pDoc = Documents.Open(Filename:=pFolder & pFilename)
pDoc.SaveAs FileName:=left(pDoc.FullName, len(pDoc.FullName)-3) &
".txt", FileFormat:=wdFormatDOSText
pDoc.Close

pFileName = Dir
Loop
 
G

Guest

Thanks again Jezebel,
I feel kind of silly, I just realized that I phrased my question about this
wrong to begin with--what I meant to say was, is there a way to save a macro
so it applies only to documents in a specific folder, and not for everything
with the normal template?

Sorry about the confusion, and thanks for bearing with me!
Jezzica85

Jezebel said:
Dim pFileName as string
Dim pDoc as word.document
Const pFolder = "C:\.......[whatever]\"
pFileName = Dir(pFolder & "*.doc")
Do while len(pFileName) > 0
set pDoc = Documents.Open(Filename:=pFolder & pFilename)
pDoc.SaveAs FileName:=left(pDoc.FullName, len(pDoc.FullName)-3) &
".txt", FileFormat:=wdFormatDOSText
pDoc.Close

pFileName = Dir
Loop




jezzica85 said:
Thank you Jezebel, but would you mind elaborating on how to apply the
macro
to all the documents in a particular folder?
Thanks!
Jezzica85
 
J

Jezebel

I think you misunderstand the relation between macros, templates, and
folders. Macros apply to whatever you apply them to; they have no inherent
relation with folders unless you specify some such relation. Nor is there
any particular connection with templates, except in the sense that macros
can be stored in templates (they can also be stored in add-ins). If a macro
is stored in a template other than normal, then it is available only when
that template, or a document based on it, is open; so typically the macro
would be used for the documents based on the template. But this is a
practical issue, not a technical requirement: the macro can do anything you
like, to any documents you like, located in any folder you choose.

In the same code I posted, the macro runs on all documents in whatever
folder you specify, regardless of what templates might be attached to those
documents.


jezzica85 said:
Thanks again Jezebel,
I feel kind of silly, I just realized that I phrased my question about
this
wrong to begin with--what I meant to say was, is there a way to save a
macro
so it applies only to documents in a specific folder, and not for
everything
with the normal template?

Sorry about the confusion, and thanks for bearing with me!
Jezzica85

Jezebel said:
Dim pFileName as string
Dim pDoc as word.document
Const pFolder = "C:\.......[whatever]\"
pFileName = Dir(pFolder & "*.doc")
Do while len(pFileName) > 0
set pDoc = Documents.Open(Filename:=pFolder & pFilename)
pDoc.SaveAs FileName:=left(pDoc.FullName, len(pDoc.FullName)-3) &
".txt", FileFormat:=wdFormatDOSText
pDoc.Close

pFileName = Dir
Loop




jezzica85 said:
Thank you Jezebel, but would you mind elaborating on how to apply the
macro
to all the documents in a particular folder?
Thanks!
Jezzica85

:



1. Is it possible to write an AutoClose macro so when a document
closes,
it
saves as a text file of the same name on the D drive?

Yes




2. If that macro is possible, is there a way to apply it to all the
documents in a folder without going through each one manually and
retyping
it?


Yes
 
G

Guest

Now I understand, thanks again Jezebel.
Jezzica85

Jezebel said:
I think you misunderstand the relation between macros, templates, and
folders. Macros apply to whatever you apply them to; they have no inherent
relation with folders unless you specify some such relation. Nor is there
any particular connection with templates, except in the sense that macros
can be stored in templates (they can also be stored in add-ins). If a macro
is stored in a template other than normal, then it is available only when
that template, or a document based on it, is open; so typically the macro
would be used for the documents based on the template. But this is a
practical issue, not a technical requirement: the macro can do anything you
like, to any documents you like, located in any folder you choose.

In the same code I posted, the macro runs on all documents in whatever
folder you specify, regardless of what templates might be attached to those
documents.


jezzica85 said:
Thanks again Jezebel,
I feel kind of silly, I just realized that I phrased my question about
this
wrong to begin with--what I meant to say was, is there a way to save a
macro
so it applies only to documents in a specific folder, and not for
everything
with the normal template?

Sorry about the confusion, and thanks for bearing with me!
Jezzica85

Jezebel said:
Dim pFileName as string
Dim pDoc as word.document
Const pFolder = "C:\.......[whatever]\"
pFileName = Dir(pFolder & "*.doc")
Do while len(pFileName) > 0
set pDoc = Documents.Open(Filename:=pFolder & pFilename)
pDoc.SaveAs FileName:=left(pDoc.FullName, len(pDoc.FullName)-3) &
".txt", FileFormat:=wdFormatDOSText
pDoc.Close

pFileName = Dir
Loop




Thank you Jezebel, but would you mind elaborating on how to apply the
macro
to all the documents in a particular folder?
Thanks!
Jezzica85

:



1. Is it possible to write an AutoClose macro so when a document
closes,
it
saves as a text file of the same name on the D drive?

Yes




2. If that macro is possible, is there a way to apply it to all the
documents in a folder without going through each one manually and
retyping
it?


Yes
 

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

Similar Threads

Mark the end of a page? 9
Paragraph alignment in a macro 2
Ends of lines and breaks 5
Updating fields automatically? 3
A wildcard question 2
Merge Two Documents 1
Macro virus 6
Spell check not working? 1

Top