Call a Userform rather than a Inputbox

D

DavidRocastle

I was wondering from the code below how would i call a userform, named
userform1 which will contain a textfield named Title, please view the code
rather than having the inputbox which is currently displayed.

-------------------------------------

Dim Title As String

Title = InputBox("Enter the Document Title:", "Title", "New Document")

ActiveDocument.BuiltInDocumentProperties("Title").Value = Title


For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType < wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
 
J

Jean-Guy Marcil

DavidRocastle was telling us:
DavidRocastle nous racontait que :
I was wondering from the code below how would i call a userform, named
userform1 which will contain a textfield named Title, please view the
code rather than having the inputbox which is currently displayed.
'_______________________________________
Dim Title As String
Dim frmTitle As UserForm1
Dim oStory As Range

Set frmTitle = New UserForm1

With frmTitle
.Show
ActiveDocument.BuiltInDocumentProperties("Title").Value = .Title.Text
End With

Unload frmTitle

Set frmTitle = Nothing

For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType < wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next
'_______________________________________

But why would you use a userform if all you need is one string of text? The
InputBOx is perfect in that case, no?

--

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

DavidRocastle

Thanks for that Jean-Guy,

I just wanted to change the appearance of it rather than have the dull input
box. How could assign an Update button to run my task?
 
J

Jean-Guy Marcil

DavidRocastle was telling us:
DavidRocastle nous racontait que :
Thanks for that Jean-Guy,

I just wanted to change the appearance of it rather than have the
dull input box. How could assign an Update button to run my task?

If you run the macro as posted, the updating will run as soon as the
userform is closed.
Just use an OK button which would have this code:

Me.Hide


--

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

Shane

In the VB Editor and with your project open, Insert -> Userform. Add
you textboxes or whatever to the form. Change colours etc etc.

Add an OK button that processes everything i.e. putting the contents
of the text box to a bookmark.

There's a wealth of info out there on userforms.

Cheers
Shane
 
S

Shane

In the VB Editor and with your project open, Insert -> Userform. Add
you textboxes or whatever to the form. Change colours etc etc.

Add an OK button that processes everything i.e. putting the contents
of the text box to a bookmark.

There's a wealth of info out there on userforms.

Cheers
Shane
 
D

DavidRocastle

Thanks for that Jean

Jean-Guy Marcil said:
DavidRocastle was telling us:
DavidRocastle nous racontait que :


If you run the macro as posted, the updating will run as soon as the
userform is closed.
Just use an OK button which would have this code:

Me.Hide


--

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