View Full Version : saving document
kenparker23
12-02-2007, 04:05 PM
I have a textbox (textbox1). I would like to assign a macro to save the document with the name in textbox1. I would like to save in a folder C:\patients. For example: if "John Smith" was in textbox 1. I would like have a macro that when activated would save the document as "John Smith" in the "patients" folder. thanks again.
TonyJollans
12-02-2007, 04:26 PM
What kind of Textbox?
kenparker23
12-02-2007, 04:46 PM
It is a textbox made with the control toolbar. It is not on a userform, just embedded into the document.
TonyJollans
12-02-2007, 04:54 PM
Then this will get you the contents ..
Document_Ref.Textbox1.Text
fumei
12-03-2007, 09:41 AM
ActiveDocument.SaveAs Filename:="c:\patients\" & _
ThisDocument.Textbox1.Text & ".doc"
Actually, you could probably skip the .doc
TonyJollans
12-03-2007, 10:10 AM
Nothing like spelling it out :)
You could skip the .Text too :D
fumei
12-03-2007, 10:27 AM
Indeed. So to REALLY spell it out...
ActiveDocument.SaveAs Filename:="c:\patients\" & ThisDocument.Textbox1
Although, as a (kind of) best practice, it is generally better to be explicit.
Also, not using the .doc makes the assumption (which of course may, or may not, be correct) that you want to save it as a Word doc file. If that is not desired, then record a SaveAs action, and look at the possible parameters for alternate formats.
kenparker23
12-03-2007, 10:29 AM
Thanks guys. It worked great. I have one more question. If I had 2 text boxes (one with last name and one with first name) and a third text box with the date. Could I do the same thing? If so how?
fumei
12-03-2007, 10:43 AM
Yes of course. Exactly the same way.
If you need to append them, then use the ampersand.
ActiveDocument.SaveAs Filename:="c:\patients\" & _
ThisDocument.Textbox1 & ThisDocument.Textbox2 & ThisDocument.Textbox3
Note that this would have no spaces between the values of the textboxes.
Note also that depending on where you are executing this from, you could also skip the ThiisDocument part.
If the macro is executed from the ThisDocument module - and you should state these kinds of things - then you could do:
ActiveDocument.SaveAs Filename:="c:\patients\" & _
Textbox1 & Textbox2 & Textbox3
You do not state what, when or how, this is being executed. This may - or may not - be significant.
"macro that when activated " is rather ambiguous.
TonyJollans
12-03-2007, 12:23 PM
Also, not using the .doc makes the assumption (which of course may, or may not, be correct) that you want to save it as a Word doc file. If that is not desired, then record a SaveAs action, and look at the possible parameters for alternate formats.
This is especially important with 2007, which has a new format. If you don't code explicitly for 97-2003 format, you will get 2007-format even if you specify a .doc suffix. So the save should really be:
.SaveAs Filename:=whatever, FileFormat:=wdFormatDocument
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.