Results 1 to 3 of 3

Thread: [FAQ's: OD] How do I change the drawing layout and/or page size?

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    [FAQ's: OD] How do I change the drawing layout and/or page size?

    Changing the drawing layout from Portrait to Landscape or Landscape to Portrait is allot different in Visio then other Office Apps. Same for changing the drawing size too. Its objects are organized differently and a bit burried down the object heirarchy.


    Visio 2003 VBA Code Example:

    VB Code:
    1. Option Explicit
    2. 'Behind ThisDocument
    3. 'Note: Assumes current open drawing is "Drawing1.vsd"
    4. Private Sub ChangeLayout()
    5.     Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
    6.     visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "2"
    7. End Sub
    8.  
    9. Private Sub ChangePageSize(ByVal strWidth As String, ByVal strHeight As String)
    10.     Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
    11.     visRowPage, visPageWidth).FormulaU = "11 in"
    12.     Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
    13.     visRowPage, visPageHeight).FormulaU = "8.5 in"
    14. End Sub
    VB Code:
    1. 'Example Usage:
    2. Private Sub Command1_Click()
    3.     ChangeLayout
    4. End Sub
    5.  
    6. Private Sub Command2_Click()
    7.     ChangePageSize "11 in", 8.5 in"
    8. End Sub
    Last edited by RobDog888; Aug 23rd, 2006 at 04:01 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [FAQ's: OD] How do I change the drawing layout and/or page size?

    You could create an interface like this:



    Visio 2003 And VB 6 Code Example:

    VB Code:
    1. Option Explicit
    2. 'Add a reference to Microsoft Visio xx.0 Object Library
    3. Private moApp As Visio.Application
    4. Private moVsd As Visio.Document
    5. Private moVsp As Visio.Page
    6.  
    7. Private Sub cmdApply_Click()
    8.     'Change the drawing layout according to the option button selection made by the user
    9.     If optLandscape.Value = True Then
    10.         moVsp.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "2"
    11.     Else
    12.         moVsp.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "1"
    13.     End If
    14.     'Change the drawing size according to the users input
    15.     '(need to do more error checking but this is just for an ex.)
    16.     If Len(txtWidth.Text) > 0 And Len(txtHeight.Text) > 0 Then
    17.         moVsp.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).FormulaU = txtWidth.Text & " in"
    18.         moVsp.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = txtHeight.Text & " in"
    19.     End If
    20. End Sub
    21.  
    22. Private Sub cmdOpen_Click()
    23.     Set moVsd = moApp.Documents.Open("C:\Development\Tips\Visio FAQ - Page Layout and Size\Drawing1.vsd")
    24.     moApp.Visible = True
    25.     Set moVsp = moVsd.Pages.Item(1)
    26.     cmdApply.Enabled = True
    27. End Sub
    28.  
    29. Private Sub Form_Load()
    30.     Set moApp = New Visio.Application
    31.     moApp.Visible = False
    32.     optLandscape.Value = True
    33.     cmdApply.Enabled = False
    34. End Sub
    35.  
    36. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    37.     Set moVsp = Nothing
    38.     moVsd.Close
    39.     Set moVsd = Nothing
    40.     moApp.Quit
    41.     Set moApp = Nothing
    42. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [FAQ's: OD] How do I change the drawing layout and/or page size?



    Visio 2003 And VB.NET 2003 Code Example:
    VB Code:
    1. [color=blue]Option [color=blue]Explicit[/color] On[/color]
    2. [color=blue]Option Strict On[/color]
    3. 'Add a reference to Microsoft Visio xx.0 Object Library
    4. [color=blue]Imports[/color] Visio = Microsoft.Office.Interop.Visio
    5.  
    6. [color=blue]Public Class[/color] Form1
    7.  
    8.     Inherits System.Windows.Forms.Form
    9.  
    10.     [color=dimgray]"Windows Form Designer generated code"[/color]
    11.  
    12.     [color=blue]Private[/color] moApp [color=blue]As[/color] Visio.Application
    13.     [color=blue]Private[/color] moVsd [color=blue]As[/color] Visio.Document
    14.  
    15.     [color=blue]Private Sub[/color] Form1_Load([color=blue]ByVal[/color] sender [color=blue]As[/color] System.[color=black]Object[/color], [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles MyBase[/color].Load
    16.         [color=darkgreen]'Create an instance of the Visio.Application[/color]
    17.         moApp = [color=blue]DirectCast[/color]([color=black]CreateObject[/color]("Visio.Application"), Visio.Application)
    18.         moApp.Visible = [color=blue]False[/color]
    19.         optLandscape.Checked = [color=blue]True[/color]
    20.         btnApply.Enabled = [color=blue]False[/color]
    21.     [color=blue]End Sub[/color]
    22.  
    23.     [color=blue]Private Sub[/color] btnOpen_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.[color=black]Object[/color], [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] btnOpen.Click
    24.         [color=darkgreen]'Open the Visio File[/color]
    25.         moVsd = moApp.Documents.[color=black]Open[/color]("C:\Development\Tips\Visio FAQ - Page Layout and Size\Drawing1.vsd")
    26.         moApp.Visible = [color=blue]True[/color]
    27.         btnApply.Enabled = [color=blue]True[/color]
    28.     [color=blue]End Sub[/color]
    29.  
    30.     [color=blue]Private Sub[/color] btnApply_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.[color=black]Object[/color], [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] btnApply.Click
    31.         [color=blue]Dim[/color] oVsp [color=blue]As[/color] Visio.Page
    32.         oVsp = [color=blue]DirectCast[/color](moVsd.Pages.[color=black]Item[/color](1), Visio.Page)
    33.         [color=darkgreen]'Change the drawing layout according to the option button selection made by the user[/color]
    34.         [color=blue]If[/color] optLandscape.Checked = [color=blue]True Then[/color]
    35.             oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
    36.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPrintProperties, [color=blue]Short[/color]), _
    37.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPrintPropertiesPageOrientation, [color=blue]Short[/color])).FormulaU = "2"
    38.         [color=blue]Else[/color]
    39.             oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
    40.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPrintProperties, [color=blue]Short[/color]), _
    41.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPrintPropertiesPageOrientation, [color=blue]Short[/color])).FormulaU = "1"
    42.         [color=blue]End If[/color]
    43.         [color=darkgreen]'Change the drawing size according to the users input[/color]
    44.         [color=blue]'(need to do more error checking but this is just for an ex.)[/color]
    45.         [color=blue]If[/color] txtWidth.TextLength > 0 [color=blue]And[/color] txtHeight.TextLength > 0 [color=blue]Then[/color]
    46.             oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
    47.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPage, [color=blue]Short[/color]), _
    48.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPageWidth, [color=blue]Short[/color])).FormulaU = txtWidth.Text & " in"
    49.             oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
    50.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPage, [color=blue]Short[/color]), _
    51.             [color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPageHeight, [color=blue]Short[/color])).FormulaU = txtHeight.Text & " in"
    52.         [color=blue]End If[/color]
    53.         oVsp = [color=blue]Nothing[/color]
    54.     [color=blue]End Sub[/color]
    55.  
    56.     [color=blue]Private Sub[/color] Form1_Closing([color=blue]ByVal[/color] sender [color=blue]As Object[/color], [color=blue]ByVal[/color] e [color=blue]As[/color] System.ComponentModel.CancelEventArgs) [color=blue]Handles MyBase[/color].Closing
    57.         moVsd.[color=black]Close()[/color]
    58.         moVsd = [color=blue]Nothing[/color]
    59.         moApp.Quit()
    60.         moApp = [color=blue]Nothing[/color]
    61.     [color=blue]End Sub[/color]
    62.  
    63. [color=blue]End Class[/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width