Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sheet Number in VBA

7 REPLIES 7
Reply
Message 1 of 8
stuartmp
1958 Views, 7 Replies

Sheet Number in VBA

Hi All
I was just wondering if it is possible to get the current sheet number through VBA?

Thanks
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: stuartmp


The sheet number is appended to the sheet name in
the browser.  You can get this name using the Name property of the Sheet
object and then extract the number from the name.  Here's an example of a
function that does this.

 

Public Function GetSheetNumber(ByVal Sheet
As Inventor.Sheet) As Integer
    Dim strSheetName As
String
    strSheetName = Sheet.Name
   

    If InStr(strSheetName, ":")
Then
        ' Extract the sheet number
from the name.
        GetSheetNumber =
CInt(Right$(strSheetName, Len(strSheetName) - InStrRev(strSheetName,
":")))
    Else
       
' This sheet is not numbered so return
zero.
        GetSheetNumber =
0
    End If
End Function



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
All I was just wondering if it is possible to get the current sheet number
through VBA? Thanks
Message 3 of 8
stuartmp
in reply to: stuartmp

Thanks Brian.

I originally had.

Dim SheetNumber as string
SheetNumber = Mid(Trim(oActiveSheet.Name), 1 + InStrR(Trim(oActiveSheet.Name), ":", vbTextCompare))


Function InStrR(ByVal sTarget As String, ByVal sFind As String, ByVal iCompare As Long) As Long

Dim P As Long, LastP As Long, Start As Long

P = InStr(1, sTarget, sFind, iCompare)

Do While P

LastP = P

P = InStr(LastP + 1, sTarget, sFind, iCompare)

Loop

InStrR = LastP

End Function


' I did not realize until I just tried it that you can not override the sheet number manually in the browser. It does not accept you renaming it to
Test:2 for example. I guess I should have tried it first. I also did not know there was a standard function for searching strings in reverse
I was just using one that I got a few year ago

Thanks for effort you put into the GetSheetNumber function. I will add it to my collection

Kind regards

Stuart Penberthy
Message 4 of 8
stuartmp
in reply to: stuartmp

Please delete Edited by: stuartmp on Oct 14, 2008 4:55 PM
Message 5 of 8
Anonymous
in reply to: stuartmp


Mid(oSheet.Name, InStr(1, oSheet.Name, ":") +
1)

 

Joe ...

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
All I was just wondering if it is possible to get the current sheet number
through VBA? Thanks
Message 6 of 8
jR0sal3s
in reply to: Anonymous

yes...

 

Public Sub x()

'The sheet number is appended to the sheet name in _
the browser. You can get this name using the Name _
property of the Sheet object and then extract the number from the name. *Brian Ekins

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim NoOfSheets As Integer
Dim CurrentSheet As Integer

NoOfSheets = oDoc.Sheets.Count

Dim strSheetName As String
strSheetName = oDoc.ActiveSheet.Name

If InStr(strSheetName, ":") Then
' Extract the sheet number from the name.
GetSheetNumber = CInt(Right$(strSheetName, Len(strSheetName) - InStrRev(strSheetName, ":")))
Else

'This sheet is not numbered so returnzero.
GetSheetNumber = 0
End If

CurrentSheet = GetSheetNumber

Debug.Print CurrentSheet
Debug.Print NoOfSheets

End Sub

Message 7 of 8
JamieVJohnson2
in reply to: jR0sal3s

Isn't the sheet number the same as the document.sheets index value?  If so;

dim sheetNo as integer = 0

For index as Integer = 1 to document.sheets.count

if documents.sheets(index).name = activesheet.name then

'sheet number found it is index.

sheetNo = index

exit for

end if

next

 

 

jvj
Message 8 of 8
jR0sal3s
in reply to: JamieVJohnson2

i am not quiet sure about that...but the solution posted by Brian Ekins seems to work fine...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report