Alejandro Gombao
New Member
- Joined
- Dec 21, 2022
- Messages
- 6
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
- Web
Hello everyone,
I'm trying to elaborate an Index for a documentation repository at my company.
First of all, I obtained a list of all files contained, and pasted in an Excel the network links to each of them.
Second, I sorted the list so all files would be just below the directory that contains them.
Then I elaborated a series of macros for the following:
- Spacing the start of the lines (aka, moving the values to the right, depending of how "deep" each file is in the repository)
- Transforming each network link into an "interactive" hyperlink that allows the user to open files directly from the Index
- Identifying which of the links are files and which are links to directories, and colouring the rows that contain the directories
Now, I would like to shorten those links so they only show "the last part of the link" which would be, obviosuly, the file/directory's name, to do so I tried to use "inStrRev" to find the position of the last "\" in the name, then substract that position to the total length of the link and then extract (with "Right") the remaining number of characters from the link.
Sadly it isn't working as intended, it shortened "random" numbers of characters from the original links.
After some debugging, I have found the "return" value of InStrRev is not as expected, and by now I'm lost on how to do this.
Here's my code. It's probably painful to watch for some of you since I started coding VBA yesterday (literally)... Hope you can help me on this
Sub AcortarNombres()
Dim Posit1 As Integer, Posit2 As Integer
Dim Nombre As String
Dim aux As String
For x = 1 To 7676
For y = 1 To 11
Set curCell2 = Cells(x, y)
If IsEmpty(curCell2) = True Then
Else:
Posit1 = 0
Posit2 = 0
aux = Right(curCell2.Value, 100)
Posit1 = InStrRev(aux, "\")
Posit2 = Len(curCell2.Value) - Posit1
Nombre = Right(curCell2.Value, Posit2)
curCell.Value = Nombre
End If
Next y
Next x
End Sub
I'm trying to elaborate an Index for a documentation repository at my company.
First of all, I obtained a list of all files contained, and pasted in an Excel the network links to each of them.
Second, I sorted the list so all files would be just below the directory that contains them.
Then I elaborated a series of macros for the following:
- Spacing the start of the lines (aka, moving the values to the right, depending of how "deep" each file is in the repository)
- Transforming each network link into an "interactive" hyperlink that allows the user to open files directly from the Index
- Identifying which of the links are files and which are links to directories, and colouring the rows that contain the directories
Now, I would like to shorten those links so they only show "the last part of the link" which would be, obviosuly, the file/directory's name, to do so I tried to use "inStrRev" to find the position of the last "\" in the name, then substract that position to the total length of the link and then extract (with "Right") the remaining number of characters from the link.
Sadly it isn't working as intended, it shortened "random" numbers of characters from the original links.
After some debugging, I have found the "return" value of InStrRev is not as expected, and by now I'm lost on how to do this.
Here's my code. It's probably painful to watch for some of you since I started coding VBA yesterday (literally)... Hope you can help me on this
Sub AcortarNombres()
Dim Posit1 As Integer, Posit2 As Integer
Dim Nombre As String
Dim aux As String
For x = 1 To 7676
For y = 1 To 11
Set curCell2 = Cells(x, y)
If IsEmpty(curCell2) = True Then
Else:
Posit1 = 0
Posit2 = 0
aux = Right(curCell2.Value, 100)
Posit1 = InStrRev(aux, "\")
Posit2 = Len(curCell2.Value) - Posit1
Nombre = Right(curCell2.Value, Posit2)
curCell.Value = Nombre
End If
Next y
Next x
End Sub