-
Apr 27th, 2006, 03:08 AM
#1
[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:
Option Explicit
'Behind ThisDocument
'Note: Assumes current open drawing is "Drawing1.vsd"
Private Sub ChangeLayout()
Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "2"
End Sub
Private Sub ChangePageSize(ByVal strWidth As String, ByVal strHeight As String)
Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
visRowPage, visPageWidth).FormulaU = "11 in"
Application.Documents("Drawing1.vsd").Pages(1).PageSheet.CellsSRC(visSectionObject, _
visRowPage, visPageHeight).FormulaU = "8.5 in"
End Sub
VB Code:
'Example Usage:
Private Sub Command1_Click()
ChangeLayout
End Sub
Private Sub Command2_Click()
ChangePageSize "11 in", 8.5 in"
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Aug 23rd, 2006, 04:01 PM
#2
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:
Option Explicit
'Add a reference to Microsoft Visio xx.0 Object Library
Private moApp As Visio.Application
Private moVsd As Visio.Document
Private moVsp As Visio.Page
Private Sub cmdApply_Click()
'Change the drawing layout according to the option button selection made by the user
If optLandscape.Value = True Then
moVsp.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "2"
Else
moVsp.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "1"
End If
'Change the drawing size according to the users input
'(need to do more error checking but this is just for an ex.)
If Len(txtWidth.Text) > 0 And Len(txtHeight.Text) > 0 Then
moVsp.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).FormulaU = txtWidth.Text & " in"
moVsp.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = txtHeight.Text & " in"
End If
End Sub
Private Sub cmdOpen_Click()
Set moVsd = moApp.Documents.Open("C:\Development\Tips\Visio FAQ - Page Layout and Size\Drawing1.vsd")
moApp.Visible = True
Set moVsp = moVsd.Pages.Item(1)
cmdApply.Enabled = True
End Sub
Private Sub Form_Load()
Set moApp = New Visio.Application
moApp.Visible = False
optLandscape.Value = True
cmdApply.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set moVsp = Nothing
moVsd.Close
Set moVsd = Nothing
moApp.Quit
Set moApp = Nothing
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Aug 23rd, 2006, 04:01 PM
#3
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:
[color=blue]Option [color=blue]Explicit[/color] On[/color]
[color=blue]Option Strict On[/color]
'Add a reference to Microsoft Visio xx.0 Object Library
[color=blue]Imports[/color] Visio = Microsoft.Office.Interop.Visio
[color=blue]Public Class[/color] Form1
Inherits System.Windows.Forms.Form
[color=dimgray]"Windows Form Designer generated code"[/color]
[color=blue]Private[/color] moApp [color=blue]As[/color] Visio.Application
[color=blue]Private[/color] moVsd [color=blue]As[/color] Visio.Document
[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
[color=darkgreen]'Create an instance of the Visio.Application[/color]
moApp = [color=blue]DirectCast[/color]([color=black]CreateObject[/color]("Visio.Application"), Visio.Application)
moApp.Visible = [color=blue]False[/color]
optLandscape.Checked = [color=blue]True[/color]
btnApply.Enabled = [color=blue]False[/color]
[color=blue]End Sub[/color]
[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
[color=darkgreen]'Open the Visio File[/color]
moVsd = moApp.Documents.[color=black]Open[/color]("C:\Development\Tips\Visio FAQ - Page Layout and Size\Drawing1.vsd")
moApp.Visible = [color=blue]True[/color]
btnApply.Enabled = [color=blue]True[/color]
[color=blue]End Sub[/color]
[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
[color=blue]Dim[/color] oVsp [color=blue]As[/color] Visio.Page
oVsp = [color=blue]DirectCast[/color](moVsd.Pages.[color=black]Item[/color](1), Visio.Page)
[color=darkgreen]'Change the drawing layout according to the option button selection made by the user[/color]
[color=blue]If[/color] optLandscape.Checked = [color=blue]True Then[/color]
oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPrintProperties, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPrintPropertiesPageOrientation, [color=blue]Short[/color])).FormulaU = "2"
[color=blue]Else[/color]
oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPrintProperties, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPrintPropertiesPageOrientation, [color=blue]Short[/color])).FormulaU = "1"
[color=blue]End If[/color]
[color=darkgreen]'Change the drawing size according to the users input[/color]
[color=blue]'(need to do more error checking but this is just for an ex.)[/color]
[color=blue]If[/color] txtWidth.TextLength > 0 [color=blue]And[/color] txtHeight.TextLength > 0 [color=blue]Then[/color]
oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPage, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPageWidth, [color=blue]Short[/color])).FormulaU = txtWidth.Text & " in"
oVsp.PageSheet.CellsSRC([color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisRowIndices.visRowPage, [color=blue]Short[/color]), _
[color=blue]CType[/color](Microsoft.Office.Interop.Visio.VisCellIndices.visPageHeight, [color=blue]Short[/color])).FormulaU = txtHeight.Text & " in"
[color=blue]End If[/color]
oVsp = [color=blue]Nothing[/color]
[color=blue]End Sub[/color]
[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
moVsd.[color=black]Close()[/color]
moVsd = [color=blue]Nothing[/color]
moApp.Quit()
moApp = [color=blue]Nothing[/color]
[color=blue]End Sub[/color]
[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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|