Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word - calculations to fill a bookmark

Status
Not open for further replies.

pendle666

Technical User
Jan 30, 2003
295
GB
Hello

My userform asks for info which is put into an offer of employment.

The Salary is entered by the user into a textbox which fills the gap at [SALARY] bookmark. If the employee is going to work shifts, the user ticks a box.

Then what I want to happen is for the [SALARY_SHIFT] bookmark to be replaced with the salary + 20%.

Can this be done?

regards
Pendle
 
From what you say, you already know how to insert text at a bookmark (something like bookmarks("salary_shift").insertafter(<text>), I suppose). So, are you asking how to compute salary + 20%? I assume you get your salary (as text) from the input box like: strSal = inputbox("input salary"). Then, you need to convert strSal to a number: fltSal = val(strSal) would do it, or fltSal = cdec(strSal) if strSal contains only numbers.

Then, fltSalAdj = 1.2*fltSal returns salary + 20%.
Then, something like strSalAdj = "$" & str(fltSalAdj)

_________________
Bob Rashkin
 
Hi pendle666,

Try calling the following macro with parameters for the bookmark’s name and new string:
Code:
Sub UpdateBookmark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
If Documents.Count > 0 Then
  If ActiveDocument.Bookmarks.Exists(BmkNm) Then
    Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    ActiveDocument.Bookmarks.Add BmkNm, BmkRng
  End If
End If
Set BmkRng = Nothing
End Sub
Note that this code doesn't replace the bookmark with the text - it updates it. That way, you can update it again later if necessary.

Cheers



[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top