How can I adjust Microsoft Word's footer height using VBA in Word 2010?
I have tried recording a macro but the height information doesn't get recorded.
It's the FooterDistance property of the PageSetup object. The example below sets it to 1":
With ActiveDocument.PageSetup
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(1)
End With
The property, that can be read or set is
activedocument.PageSetup.FooterDistance
Unit is in dots based on a 72 DPI, meaning fhat if you set the value to 72, that will give you a 2.54 cm or 1 inch footer
Hope that helps
Daniel
I didn't see an answer for this, so here is mine:
The height of an empty footer is the BottomMargin minus the FooterDistance.
The margin size determines the maximum size for the whole footer (including the FooterDistance (white space)).
The FooterDistance will determine how close to the edge of the page the text will get rendered. (be aware that your actual printer margins will chop off stuff that is too close to the edge)
Note: If you already have stuff in your footer and if the text and/or images in the footer has a larger total height - Word will make the footer taller to hold it all.
The sample code below will resize your footer.
Dim sHght As Single
With ActiveDocument.PageSetup
sHght = .BottomMargin ' get existing margin in points
.BottomMargin = sHght + 10 ' increase margin (size of space for footer)
.FooterDistance = CentimetersToPoints(1) ' set to suit your printer
End With
Related
I have a anchored MSGraph Chart object on my form to stretch left and bottom. It stretches well but the fonts also stretch. How do I maintain the same font size for all the Data labels but still be able to view the graph in full size on stretched or zoomed mode? My aim is to keep font sizes for all Data labels and Axis to 11pt. The original font size for the Data Labels and Axis is 8pt
Edit:
I have notice that when I select the Zoom or Stretch features in the Chart's properties sheet, the chart stretches and the so does the fonts. This does not happen if I select Clip
Is it possible to make the chart stretch whilst maintaining the font sizes to 11pt? I am asking this because when I looked at the chart on a 4:3 screen today, some fonts were barely visible. Please see the image of my current graph and together with its properties settings below:
I have inserted a Stacked Layout with two cells onto the the form, then inserted the chart object in the first cell and left the second cell empty.
A good thing is that an empty cell can be anchored to Strech when the form resizes to suit the screen's aspect ratio.
I then adjusted the height of the blank cell and anchored both the object and the blank cell to Sctrech Down and Across.
On the chart properties, the chart Size Mode must be set to Strecth
Then used the below code on the form open event:
Note: This code requires the use of Microsoft Graph Object Library which should be added using the Tools -> References feature on the code editor.
I am using Microsoft Graph 16.0 Object Library.
I shall be exploring how to use latebinding inorder to avoid this step or perhalps somone can comment.
Dim myChart As Graph.Chart
Dim myChartSeries As Graph.Series
Dim mySeriesDataLabel As Graph.DataLabel
Set myChart = Me.myGraph.Object
For Each myChartSeries In myChart.SeriesCollection
For Each mySeriesDataLabel In myChartSeries.DataLabels
mySeriesDataLabel.Font.Name = "Times New Roman"
mySeriesDataLabel.Font.FontStyle = "Normal"
mySeriesDataLabel.Font.Size = 8
Next mySeriesDataLabel
Next myChartSeries
With Me.myGraph.Axes(1).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
With Me.myGraph.Axes(2).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
Without Anchoring:
After Anchoring:
I have added an Label on my Chart tab, but when I try to change it's font all of the fields are greyed out. I have searched enough but didn't find any solution. I am attaching a screenshot of my chart tab.
I want to change the font properties of this Label 10 on the chart tab. Is there a way I can access the properties by VBA.
To change the text I recorded a macro.
ActiveChart.Shapes("Label 10").Select
Selection.Characters.Text = "Mohit"
ActiveChart.ChartArea.Select
I tried the line code:
Selection.TextFrame.Characters.Font.Size = 20
but it doesn't work. is there a way to change the color and font size of this label ?
Alternate that I am using now
Now I am using Rectangle shape instead of Label. What I wanted to acheive was to display the name of the selected button ( PV , Terrorism or SRCC ) as an indication that this button have been selected. So I clicked PV and my series changed and Rectangle displayed the name of selected Peril.
Now if I select SRCC again the same thing happens.
For the code I only have to change the text of the rectangle every-time a button is pressed as I preset the font and size of text once which remains the same. I wasn't able to change the font and size of text with a label.
ActiveChart.Shapes("Label 10").Select
With Selection
.Characters.Text = "Mohit"
.Font.Size = 20
End With
or you can avoid Select/Selection accessing your Chart object by its name:
With Charts("ChartName").Shapes("Label 10").TextFrame2.TextRange
.Text = "Mohit"
.Font.Size = 20
End With
Label text to grow on left side while making the right side fixed in vb.net.Image is attached for better understanding
Label text to grow on left side:-
What you need is to set your text label to be right-justified. Showing the part of your code related to creating and populating the label (the one displaying the total amount) will help.
You could set Autosize = False and choose TextAllign = *right. The actual label wouldn't grow, so you'd need to set a 'sufficient' width.
Alternative is to do it via code:
'find the current right alignment position
Dim rightAlign As Integer = Label1.Left + Label1.Width
'set the text (assumes AutoSize is set to True)
Label1.Text = value
'adjust position so the right hand point is in the same position as before
Label1.Left = rightAlign - Label1.Width
Depending on how your form is laid out, you can dock the label to the right and set:
Label.Dock = DockStyle.Right
Label.AutoSize = True
This will make your label expand to the left. Docking to the right will put your label at the top of the form unless you have an appropriate layout.
I have a user form containg a frame. During runtime, the user can add controls to this frame. Ultimately, the added controls can exceed the size of the frame. In this case I would like to increase the insideheight of the frame. So my vertical scrollbar does cover the whole area.
frm.ScrollHeight = .InsideHeight
How do I do this?
The .InsideHeight is not responsible for the scrollbar. However, the .ScrollHeight is. While adding new controls, this height must be increased.
When adding a new set of controls execute this:
Exchange 50 with the height of your control.
Dim scrHeight As Integer
With frm
scrHeight = .ScrollHeight
.ScrollHeight = scrHeight + 50
End With
I am creating an add-in using VB.NET VSTO for MS-Word. In this program I need to retrieve the details such as Location (Left, Top) and Size (Height, Weight) of all the images on the document. I also want to retrieve the page number where the image is located. I use the following code,
Dim i As Integer
For i = 1 To Globals.ThisAddIn.Application.ActiveDocument.InlineShapes.Count
If Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).Type = Word.WdInlineShapeType.wdInlineShapePicture Then
strHeight = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).ScaleHeight()
strWidth = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).ScaleWidth()
End If
Next i
However, this can only retrieve the Size (Height, Weight). How to get the Location (Left, Top) and page number of the image?
By its very nature, an InlineShape doesn't have a positionable top and left. It's, well, inline, which means it exists in the text layer of the document and the location floats depending on the text and/or other content before it. If the item is on page 2, and you insert 25 lines of text or another picture before InlineShape(i), said shape will float down to page 3 (or 4 or whatever.)
The height and width ARE accessible, simply by using .Height and .Width. ScaleHeight and ScaleWidth are properties that reflect the size of the object in the document relative to the original size of the object. You probably want to store the height and width as strings, though, since the property returns a single (numeric) value. For height and width:
Dim i As Integer
Dim shp as InlineShape
For i = 1 To Globals.ThisAddIn.Application.ActiveDocument.InlineShapes.Count
shp = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i)
If shp.Type = Word.WdInlineShapeType.wdInlineShapePicture Then
strHeight = shp.Height.ToString()
strWidth = shp.Width.ToString()
End If
Next i
To get the page number, you have to reference the range of the InlineShape.
shp.Range.get_Information(Word.WdInformation.wdActiveEndPageNumber)
You can also get the top and left position of the image (although it might not do you any good, depending on why you want it). The get_Information method also has wdHorizontalPositionRelativeToPage and wdVerticalPositionRelativeToPage