you excuse my tongue

F

fedora

Good morning to everybody. I have windows xp service pack 2 with word 2003.
With a button, i would like to save with name the forms field document
(protégé) taking the name from a text form field name, field no. 3, max 25
characters (if number lower, all) not to be to type in it every time. And
feasible that with macro? Is it possible also to choose where to save it? ex.
desktop folder. Friends thanks. if possible, step by step please.
 
H

Helmut Weber

Hi Fedora,

like this, to get you started.

Private Sub CommandButton1_Click()
Dim sPth As String
Dim sNam As String
sPth = "c:\test\"
sNam = ActiveDocument.FormFields(1).Result
If Len(sNam) > 25 Then
MsgBox "too long"
Else
ActiveDocument.SaveAs sPth & sNam & ".doc"
End If
End Sub

assuming, you have a commandbutton from
the control toolbox, or whatever it is called in French, I guess.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
F

fedora

Well Helmut, thanks. I would however like if the fieldname is >=25, take the
first 25 characters, non' too long' but save any way. if it is difficult I
entirely take the name of the field. in the same Private Sub
CommandButton1_Click () would like to insert an condition which always checks
if "c:\test\" there is already, otherwise create it. is it possible? Thanks
many. Greetings from, Tuscan, Italy. Ciao Fedora
 
H

Helmut Weber

Hi Fedora,

if you want the left 25 characters, then

sName= left(sNam, 25)

This works even if there are less then 25 characters.

To check, whether a directory exists, etc.

If Dir("c:\testdir\", vbDirectory) = "" Then
MkDir "c:\testdir\"
End If


--
HTH

Helmut Weber, MVP WordVBA

"red.sys" & chr$(64) & "t-online.de"
Win XP, Office 2003
 
F

fedora

hi helmut, really professional, punctual and effective. Everything works to
wonder. thanks, many thanks. you are good.
Fedora.
 

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