DialogueBox

  • Thread starter yourenotathomenow
  • Start date
Y

yourenotathomenow

I'm stuck with an application which won't put a tiltle or the date in
my letter templates. I've set up macros for each title, ie MR, MISS,
MS & MRS, the 'MR' one is below. I want to get rid of the 4 macros
and replace them with one, but before it runs I want a box from which
I can choose either MR, MISS, MS or MRS, then, when I've chosen, for
the macro to run, putting in the title I've chosen - and the date.

Sub mr


' mr Macro
'
'
Selection.TypeText Text:="MR "
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveDown Unit:=wdLine, Count:=5
Selection.MoveRight Unit:=wdCharacter, Count:=6
Selection.InsertDateTime DateTimeFormat:="dd.MM.yyyy",
InsertAsField:= _
False, DateLanguage:=wdEnglishUK,
CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.MoveDown Unit:=wdLine, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=5
Selection.TypeText Text:="MR"
End Sub
 
G

Greg Maxey

I think that you are going about this all wrong (i.e., all of the
Selection.TypeText business).

I suggest that you: 1) place a bookmark (named "Title") in your template at
the location you want the first instance to appear. 2) Put a CreateDate
field in the postion you want the date to appear. 3) Add a REF field { REF
"Title" } where you want the second instance of title to appear. 4) Create a
UserForm with a single combobox and command button to display the dialog
form which you select the title:

Private Sub UserForm_Initialize()
Dim arrTitles() As String
arrTitles = Split("Mr.,Mrs,Miss,Ms", ",")
Me.ComboBox1.List = arrTitles
End Sub

Private Sub CommandButton1_Click()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Bookmarks("Title").Range
oRng.Text = Me.ComboBox1.Value
With ActiveDocument
.Bookmarks.Add "Title", oRng
.Fields.Update
End With
Me.Hide
End Sub

See: http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

5) Add and Auto_New macro that displays a UserForm when a new document is
created using your template:

Sub Auto_New()
Dim myFrm As UserForm1
Set myFrm = New UserForm1
myFrm.Show
Unload myFrm
Set myFrm = Nothing
End Sub
 
Y

yourenotathomenow

I think that you are going about this all wrong (i.e., all of the
Selection.TypeText business).

I suggest that you:  1) place a bookmark (named "Title") in your template at
the location you want the first instance to appear.  2) Put a CreateDate
field in the postion you want the date to appear.  3) Add a REF field {REF
"Title" } where you want the second instance of title to appear. 4) Create a
UserForm with a single combobox and command button to display the dialog
form which you select the title:

Private Sub UserForm_Initialize()
Dim arrTitles() As String
arrTitles = Split("Mr.,Mrs,Miss,Ms", ",")
Me.ComboBox1.List = arrTitles
End Sub

Private Sub CommandButton1_Click()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Bookmarks("Title").Range
oRng.Text = Me.ComboBox1.Value
With ActiveDocument
  .Bookmarks.Add "Title", oRng
  .Fields.Update
End With
Me.Hide
End Sub

See:  http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

5) Add and Auto_New macro that displays a UserForm when a new document is
created using your template:

Sub Auto_New()
Dim myFrm As UserForm1
Set myFrm = New UserForm1
myFrm.Show
Unload myFrm
Set myFrm = Nothing
End Sub









--
Greg Maxey -  Word MVP

My web sitehttp://gregmaxey.mvps.org
Word MVP web sitehttp://word.mvps.org- Hide quoted text -

- Show quoted text -

Thanks, but I can't get it to work and I'm totally lost. Better read
up on Word VBA a bit more!
 

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