last value from array

T

TM

Hi,

I need some help...

I trying to write some VBA code to detect a file extention and I'm stuck
I've used the split function to put everything in an array. But how can I
get to the last value of my array ?

Can anyone please help me ?



## START

Dim strName As String
Dim strType As String
Dim strWords() As String
Dim intWordsAantal As Integer

With Dialogs(wdDialogInsertPicture)
If .Display Then
strName = WordBasic.FilenameInfo$(.Name, 1)
End If
End With

strWords = Split(strName, ".")
intWordsAantal = 0
For Each Item In strWords
intWordsAantal = intWordsAantal + 1
Next

strType = strWords(intWordsAantal ) ' DOES NOT WORK

## END



Kind regards,

TM
 
J

Jonathan West

Hi TM

You can get the extension much more simply, like this


Dim strName As String
Dim strType As String

With Dialogs(wdDialogInsertPicture)
If .Display Then
strName = WordBasic.FilenameInfo$(.Name, 1)
End If
End With

strType = Mid$(strName, InstrRev(strName, ".") + 1)
 
M

mbaird

strWords(UBound(strWords)

or an alternative method

Mid(strFilename, InStrRev(strFilename, ".") + 1, Len(strFilename))

Mark Baird
 

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