VBA Change Sheet Size

VBA Change Sheet Size

Anonymous
Not applicable
3,144 Views
2 Replies
Message 1 of 3

VBA Change Sheet Size

Anonymous
Not applicable

I am having an issue with changing sheet sizes using VBA. Due to the constraints under which my borders and title blocks were created, inventor forces me to delete the current border before changing the sheet size. I have 5 different borders and 2 title blocks.

 

-Borders
"A0 Border (13x8 Zone)"
"A1 Border (8x6 Zone)"
"A2 Border (6x4 Zone)"
"A3 Border (4x3 Zone)"
"A4 Border (No Zones)"

 

-Title Blocks
Title Block 1 - All sizes except for A4
Title Block 2 - A4 Only


I have a good idea of what I need to do, but I'm having trouble changing the sheet size. This is the extent of the code that I know actually works:

Thanks for the help!

 

Option Explicit

Private oDoc As DrawingDocument
Private oSheet As Sheet
Private oBorderDef As BorderDefinition
Private oBorder As Border

Set oDoc = ThisApplication.ActiveDocument
Set oSheet = oDoc.ActiveSheet
Set oBorderDef = oDoc.BorderDefinitions.Item("A0 Border (13x8 Zone)")

Private Sub UserForm_Initialize()
    cmbPageSize.AddItem ("A0")
    cmbPageSize.AddItem ("A1")
    cmbPageSize.AddItem ("A2")
    cmbPageSize.AddItem ("A3")
    cmbPageSize.AddItem ("A4")
End Sub

Private Sub cmbPageSize_Change()
    Select Case cmbPageSize.Value
        Case "A0"
            MsgBox ("A0")

     'Delete Existing Border
     oSheet.Border.Delete

     'Delete Existing Title Block

     'Change Sheet Size To A0

     'Place Border "A0 Border (13x8 Zone)"

     'Place Title Block "1"

        Case "A1"
            MsgBox ("A1")

     'Delete Existing Border
     oSheet.Border.Delete

     'Delete Existing Title Block

     'Change Sheet Size To A1

     'Place Border "A1 Border (8x6 Zone)"

     'Place Title Block "1"

        Case "A2"
            MsgBox ("A2")

     'Delete Existing Border
     oSheet.Border.Delete

     'Delete Existing Title Block

     'Change Sheet Size To A2

     'Place Border "A2 Border (6x4 Zone)"

     'Place Title Block "1"

        Case "A3"
     MsgBox ("A3")

     'Delete Existing Border
     oSheet.Border.Delete

     'Delete Existing Title Block

     'Change Sheet Size To A3

     'Place Border "A3 Border (4x3 Zone)"

     'Place Title Block "1"

        Case "A4"
            MsgBox ("A4")

     'Delete Existing Border
     oSheet.Border.Delete

     'Delete Existing Title Block

     'Change Sheet Size To A4

     'Place Border "A4 Border (No Zones)"

     'Place Title Block "2"

    End Select
End Sub

 

3,145 Views
2 Replies
Replies (2)
Message 2 of 3

Vladimir.Ananyev
Alumni
Alumni

Sheet size is controlled by Sheet.Size property.

Please try this sample code.

Private Sub ChangeSheetSize()

  Dim oDoc As DrawingDocument
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim oSheet As Sheet
  Set oSheet = oDoc.ActiveSheet
  
  'get current size
  Dim Size As DrawingSheetSizeEnum
  Size = oSheet.Size
  
  'set new size
  oSheet.Size = DrawingSheetSizeEnum.kA0DrawingSheetSize
  
  'update sheet to see results
  oSheet.Update
  
End Sub 'ChangeSheetSize

 Cheers


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

Anonymous
Not applicable

Vladimir,

 

Is there a way to remove unused sheet sizes from this list? We have some that we do not use and wanted to explore removing them. We are using Inventor 2015 PDS.

image.jpg

0 Likes