Change docname from docxxx to (docxxx-1)

C

camilla

Hi
I create a new documetn based on a template and it get the name for example
Document11. Now I need to activate the document I create before, Document10.

Thanks for any help
 
M

Malcolm Smith

Let's see if this works. Note that I am doing this 'blind' and without
coffee, so anything could happen.

You would then call this routine, below, with the call:


GetPreviousInstance ActiveDocument


Hope that this helps

- Malc
www.dragondrop.com


Sub GetPreviousInstance(oDocument As Document)

Dim sDocumentName As String
Dim sDocumentNumber As String
Dim nDocumentNumber As Long

Dim oDoc As Document


sDocumentName = oDocument.Name

' Make sure that the current document is called DocumentXXX
If InStr(1, sDocumentName, "Document", vbTextCompare) = 1 Then
sDocumentNumber = Right$(sDocumentName, Len(sDocumentName) -
Len("Document"))
nDocumentNumber = Val(sDocumentNumber)
If nDocumentNumber > 1 Then
nDocumentNumber = nDocumentNumber - 1
sDocumentNumber = Trim$(Str$(nDocumentNumber))
sDocumentName = "Document" & sDocumentNumber

' Active the 'previous' document if it is open
For Each oDoc In Documents
If oDoc.Name = sDocumentName Then
oDoc.Activate
Exit For
End If
Next oDoc

End If
End If

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