Microsoft Office Tutorials and References
In Depth Information
Entering Data Easily Using a Custom Dialog Box
'Variable declaration¶
Dim frm As frmUserInput¶
Dim doc As Word.Document¶
Set doc = ActiveDocument¶
If doc.Bookmarks.Count < 1 Then¶
MsgBox "Invalide document. " & _¶
"No bookmarks could be found.", _¶
vbCritical + vbOKOnly¶
Exit Sub¶
End If¶
Set frm = New frmUserInput¶
GetDataFromDocument frm, doc¶
frm.Show¶
If frm.Tag = "OK" Then¶
PutDataIntoDocument frm, doc¶
End If¶
Unload frm¶
If doc.Bookmarks.Exists("txtStartBody") Then¶
doc.Bookmarks("txtStartBody").Range.Select¶
End If¶
End Sub¶
' * * * * *¶
Sub GetDataFromDocument(frm As UserForm, doc As Word.Document)¶
'Variable declaration¶
Dim ctl As MSForms.Control¶
Dim firstControl As Boolean¶
For Each ctl In frm.Controls¶
If doc.Bookmarks.Exists(ctl.Name) Then¶
ctl.Text = doc.Bookmarks(ctl.Name).Range.Text¶
If Not firstControl Then¶
ctl.SelStart = 0¶
ctl.SelLength = Len(ctl.Text)¶
firstControl = True¶
End If¶
End If¶
Next¶
End Sub¶
' * * * * *¶
Sub PutDataIntoDocument(frm As UserForm, doc As Word.Document)¶
'Variable declaration¶
Dim ctl As MSForms.Control¶
Dim rng As Word.Range¶
For Each ctl In frm.Controls¶
If doc.Bookmarks.Exists(ctl.Name) Then¶
Set rng = doc.Bookmarks(ctl.Name).Range¶
rng.Text = ctl.Text¶
doc.Bookmarks.Add Name:=ctl.Name, Range:=rng¶
End If¶
Next¶
End Sub¶
Wrd
Search JabSto ::




Custom Search