Why does lLenLFileNam + 1 = 35, when lLenLFileNam = 8, one line higher?

M

marc

Hi. When I tried to run the vba macro below on a Word
document, the long variable "lLenLFileNam" equalled 8, on
the line containing the following code:
lLenLFileNam = InStrRev(strFulNam, "\")
On the next line, I tried to add 1 to lLenLFileNam, as
follows:
lCounter1 = lLenLFileNam + 1
Usually 8+1=9, but on this line lCounter1 was equal to 35.
What did I do wrong?

Thanks,
Marc

Here's my macro:

Private Sub btnPath1LevlHigher_Click()
'
' Macro recorded 8/23/2004 by Marc B. Hankin
'
frmMenuGnlAccess.Hide
Dim strFulNam As String, strPathFul As String,
strDirNamLow As String
Dim lLenLFileNam As Long, lCounter1 As Long,
lCounter2 As Long, lStrFulNam As Long

Dim MyPath As DataObject
Set MyPath = New DataObject

strFulNam = ActiveDocument.FullName
MsgBox strFulNam

lLenLFileNam = InStrRev(strFulNam, "\")
lCounter1 = lLenLFileNam + 1

lStrFulNam = Len(strFulNam)
lStrFulNam = lStrFulNam - lCounter1
strPathFul = Left(strFulNam, lStrFulNam)

lLenLFileNam = InStrRev(strPathFul, "\")
strFulNam = Left(strPathFul, lLenLFileNam)

'Selection.Text = strFulNam
'Selection.Text = strPathFul

MyPath.SetText strPathFul
MyPath.PutInClipboard
'
End Sub
 
J

Jezebel

Can't see where the problem is, but with those reverse string look-ups, the
code is kind of hard to follow. If all you're trying to do is get the
document's name and path, you can use:

With ActiveDocument
strFulNam = .Name
strPathFul = left(.FullName, len(.FullName)-Len(.Name))
End with
 

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