Addition (Newbie): 17 + 1 usually equals 18, What am I doing wro

M

Marceepoo

1. The following code is from a userform in MS Word, and is intended to
Title Cap the selection, and remove all spaces.
2. The problem is the line: intCounter = iStrSelektion + 1
3. In debug mode, I get 17 as the value of iStrSelektion (when I hover the
cursor over it), but I get zero (0) when I hover the cursor over intCounter
4. Why don't I get 18? What am I doing wrong?

Any ideas would be much appreciated.
Marc
Here's the code...

Private Sub btnRemovSpcsNdInitCap_Click()
Me.Hide
'
Dim MyData As DataObject
Dim strClip As String

Dim strSelektion As String, strCkChar As String, strHoldChars As String
Dim iStrSelektion As Integer, intCounter As Integer

Selection.Range.Case = wdTitleWord
strSelektion = Selection
iStrSelektion = Len(strSelektion)
intCounter = iStrSelektion + 1
strCkChar = ""
strHoldChars = ""

Do While intCounter > 0
intCounter = intCounter - 1
strCkChar = Mid(strSelektion, intCounter, 1)
'MsgBox "strCkChar =" & strCkChar
If strCkChar = Chr(32) Then strCkChar = ""
If strCkChar = Chr(64) Then strCkChar = ""
If strCkChar = Chr(160) Then strCkChar = ""
strHoldChars = strHoldChars & strCkChar
Loop
'MsgBox strHoldChars
'Selection.TypeParagraph 'Hit Enter key
'Selection.EndKey Unit:=wdStory 'Ctrl-End, go to bottom
'Selection.TypeText Text:=strHoldChars

Set MyData = New DataObject

MyData.SetText strHoldChars
MyData.PutInClipboard
'
End Sub
 

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