A
andreas
Dear Experts:
below code snippet tries to insert a drawing canvas in the current
document. I would like the width of the canvas to match the printable
area of the document (by subtracting the Left and Right Margin from
the page width). Running the macro I get a runtime error 91 on the
"Width"-portion of the code.
The "width" coding is apparently false. How can I amend the code so
that it is working?
Help is much appreciated. Thank you very much in advance.
Sub InsertCanvasWidthPrintableArea()
Dim shpCanvas As Shape
Dim sect As Section
'Add a new drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes.AddCanvas( _
Left:=70, _
Top:=75, _
Width:=sect.PageSetup.PageWidth - _
sect.PageSetup.LeftMargin - _
sect.PageSetup.RightMargin, _
Height:=250)
With shpCanvas
.Visible = msoTrue
.Select
End With
Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
End Sub
I know that inserting a canvas through the menu results in the canvas'
width matching exactly the printable area of the document (page width
minus left marging minus right margin). But still I wish to know the
right coding for this if done by VBA.
below code snippet tries to insert a drawing canvas in the current
document. I would like the width of the canvas to match the printable
area of the document (by subtracting the Left and Right Margin from
the page width). Running the macro I get a runtime error 91 on the
"Width"-portion of the code.
The "width" coding is apparently false. How can I amend the code so
that it is working?
Help is much appreciated. Thank you very much in advance.
Sub InsertCanvasWidthPrintableArea()
Dim shpCanvas As Shape
Dim sect As Section
'Add a new drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes.AddCanvas( _
Left:=70, _
Top:=75, _
Width:=sect.PageSetup.PageWidth - _
sect.PageSetup.LeftMargin - _
sect.PageSetup.RightMargin, _
Height:=250)
With shpCanvas
.Visible = msoTrue
.Select
End With
Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
End Sub
I know that inserting a canvas through the menu results in the canvas'
width matching exactly the printable area of the document (page width
minus left marging minus right margin). But still I wish to know the
right coding for this if done by VBA.