saving

J

james

hi everyone, it might sound strange, but bear with me.

I have a new document each time which the user types in.
They will then press a button to run a macro which:

-saves the file under a unique name

-automatically closes the file

I am fine with closing the file, it's the saving part i'm
having trouble with.

The user will supply their own unique name to save it
under, which they will type as the first line of the new
document. what i need a macro to do is to take
everything that is written on the first line of the
document and save it under that name.

eg. if the user is writing about cabbage number 5639 the
only thing on the first line will be "cabbage 5639"
(centre justified if that makes any difference)

as a last question will it matter if there is no ".doc"
on the end of the name at the top?
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < james > écrivait :
In this message, < james > wrote:

|| hi everyone, it might sound strange, but bear with me.
||
|| I have a new document each time which the user types in.
|| They will then press a button to run a macro which:
||
|| -saves the file under a unique name
||
|| -automatically closes the file
||
|| I am fine with closing the file, it's the saving part i'm
|| having trouble with.
||
|| The user will supply their own unique name to save it
|| under, which they will type as the first line of the new
|| document. what i need a macro to do is to take
|| everything that is written on the first line of the
|| document and save it under that name.
||
|| eg. if the user is writing about cabbage number 5639 the
|| only thing on the first line will be "cabbage 5639"
|| (centre justified if that makes any difference)
||
|| as a last question will it matter if there is no ".doc"
|| on the end of the name at the top?

Try something like this:

'_______________________________________
Dim DocName As Range

With ActiveDocument
Set DocName = .Paragraphs(1).Range
DocName.MoveEnd wdCharacter, -1

.SaveAs DocName.Text
End With
'_______________________________________

No, you do not need the ".doc" in the document text.
This code will save the document in the currently active folder. You may
want to specify a path.
Also, be weary of letting users choose a "unique" name... Murphy says that
they will inevitably choose a non-unique name!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < james > écrivait :
In this message, < james > wrote:

| merci jean, c'est tres bon.

De rien!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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