I'm trying to standardize the format the bullets of individual shapes but am not getting the results I want. The code is below.
The results I'm looking for are for the first level to have no bullet or indent and the rest of the bullets to be slightly indented from the start of the text of the previous level and the shapes alternating between dot and dash.
I've spent a couple of hours researching but haven't made any advances except to learn that I shouldn't use rulers. I don't understand what I should use instead for the indenting.
When I apply them to an existing shape, nothing works out as planned. I also can't get them to update automatically and have to go to the paragraph/bullet button on the ribbon for it to take efect.
Thanks in advance for your help.
Option Explicit
Global Const emDefaultStyleSpaceWithin = 0.9
Global Const emDefaultStyleSpaceBefore = 0.4
Global Const emDefaultStyleSpaceAfter = 0
Public Sub SetParagraphFormat()
Dim oParagraphFormat As ParagraphFormat
Dim Level As Single
Set oParagraphFormat = ActiveWindow.Selection.textRange.ParagraphFormat
With oParagraphFormat
' Set line spacing
If emDefaultStyleSpaceWithin Then
.LineRuleWithin = msoTrue
.SpaceWithin = emDefaultStyleSpaceWithin
Else
.SpaceWithin = 0
End If
If emDefaultStyleSpaceBefore Then
.LineRuleBefore = msoTrue
.SpaceBefore = emDefaultStyleSpaceBefore
Else
.SpaceBefore = 0
End If
.LineRuleAfter = msoTrue
.SpaceAfter = 0
' Set bullet format
.Bullet.RelativeSize = 1
For Level = 1 To 5
Select Case Level
Case 1
.Bullet.font.Name = "Arial"
.Bullet.Character = 8226
.Bullet.Visible = msoFalse
Case 2
.Bullet.font.Name = "Arial"
.Bullet.Character = 8226
Case 3
.Bullet.font.Name = "Arial"
.Bullet.Character = 8211
Case 4
.Bullet.font.Name = "Arial"
.Bullet.Character = 8226
Case 5
.Bullet.font.Name = "Arial"
.Bullet.Character = 8211
End Select
Next Level
End With
With ActiveWindow.Selection.ShapeRange.textFrame.Ruler
With .Levels(1)
.FirstMargin = 0
.LeftMargin = 0
End With
With .Levels(2)
.FirstMargin = 3
.LeftMargin = 17
End With
With .Levels(3)
.FirstMargin = 20
.LeftMargin = 30
End With
With .Levels(4)
.FirstMargin = 33
.LeftMargin = 45
End With
With .Levels(5)
.FirstMargin = 48
.LeftMargin = 51
End With
End With
End Sub
Related
I am working on a program and one feature is to show a graph of accrued points by game. I have successfully created the graph but cannot work out how to get rid of the big gaps at either side. I have tried reducing padding and margins to 0 but to no avail. Any help would be greatly appreciated. :)
Image of graph:
Chart1.Series.Clear()
Chart1.Titles.Clear()
Chart1.ChartAreas.Clear()
Chart1.Show()
Chart1.AlignDataPointsByAxisLabel()
Chart1.Titles.Add(names(search))
Chart1.ChartAreas.Add("Default")
With Chart1.ChartAreas("Default")
.AxisX.Interval() = 5
.AxisY.Interval() = 1
.AxisY.Title = "Number of Wins"
.AxisX.Title = "Game"
.AxisX.CustomLabels.Add(0, 60, "low")
End With
Chart1.SetBounds(270, 200, 510, 250)
Dim ref As Integer = 0
For Each item As DictionaryEntry In gamespoints
If item.Value > 0 Then
ref = ref + 1
Chart1.Series.Add(item.Key)
If item.Value = max And ref Mod 2 = 0 Then
Chart1.Series(item.Key).Color = Color.Green
ElseIf item.Value = max Then
Chart1.Series(item.Key).Color = Color.LimeGreen
ElseIf ref Mod 2 = 0 Then
Chart1.Series(item.Key).Color = Color.Black
Else
Chart1.Series(item.Key).Color = Color.DarkGray
End If
Chart1.Series(item.Key).Points.AddXY(0, item.Value)
End If
Next
working in vb.net in Visual Studio on a datagridview.
The rows are days of the week. The rows all alternate backcolor (variables LightColour1 and LightColour2), then the weekend rows are variable WeekendRowsColour. That's all easy enough, but now I have to make the entire final column white. But I can't seem to override the row colors no matter how I approach it. Any advice?
Here's my code section:
For r = 0 To 27
dgv.Rows.Add()
dgv.Rows(r).Cells(0).Value = Format(nDate, "ddd")
dgv.Rows(r).Cells(1).Value = Format(nDate, "d/MM/yyyy")
If Format(nDate, "ddd") = "Sat" Or Format(nDate, "ddd") = "Sun" Then
dgv.Rows(r).DefaultCellStyle.BackColor = WeekendRowsColour
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = WeekendRowsSelColour
Else
If r Mod 2 = 0 Then 'even row
dgv.Rows(r).DefaultCellStyle.BackColor = LightColour1
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = SelLightColour1
Else 'alternate row
dgv.Rows(r).DefaultCellStyle.BackColor = LightColour2
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = SelLightColour2
End If
End If
nDate = DateAdd(DateInterval.Day, 1, nDate)
Next
dgv.Columns(dgv.Columns.Count - 1).DefaultCellStyle.BackColor = Color.White
But no matter how I approach it, the last column comes out the default color. My best success has been setting the backcolor and alternatingrowsbackcolor of the rows programmatically, and setting the column properties to white in the designer, but that doesn't overwrite the alternating rows or the weekend colors.
Pulling my hair out here!
You have to set it inside the loop per cell like this:
For r = 0 To 27
dgv.Rows.Add()
dgv.Rows(r).Cells(0).Value = Format(nDate, "ddd")
dgv.Rows(r).Cells(1).Value = Format(nDate, "d/MM/yyyy")
If Format(nDate, "ddd") = "Sat" Or Format(nDate, "ddd") = "Sun" Then
dgv.Rows(r).DefaultCellStyle.BackColor = WeekendRowsColour
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = WeekendRowsSelColour
Else
If r Mod 2 = 0 Then 'even row
dgv.Rows(r).DefaultCellStyle.BackColor = LightColour1
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = SelLightColour1
Else 'alternate row
dgv.Rows(r).DefaultCellStyle.BackColor = LightColour2
dgv.Rows(r).DefaultCellStyle.SelectionBackColor = SelLightColour2
End If
End If
nDate = DateAdd(DateInterval.Day, 1, nDate)
dgv.Rows(r).Cells(dgv.Columns.Count-1).Style.BackColor = Color.White
Next
this is my code and I want to re-execute it so that the next column has the exact same code repeated on it. That is, D:28 moves to E:28 and range E:110:I120 moves to F110:J120. I am having trouble finding a loop that does this, can anyone please help. My code is,
Sub Rebuild()
tonnes = Range("D28").Value
If tonnes > 2600000 Then
Range("E110:I120").Select
Selection.Copy
Range("E18:I28").Select
ActiveSheet.Paste
Else:
Range("E18:I28").Interior.Color = xlNone
Range("E18:I18") = ""
Range("E19:I19") = ""
Range("E20:I20") = 0
Range("E21:I21") = 2.4
Range("E22:I22") = "=E21+E20"
Range("E23:I23") = "=24 - E22"
Range("E24:I24") = "=100 * E23 / 24"
Range("E25:I25") = 3000
Range("E26:I26") = "=E25 * E23"
Range("E27:I27") = "=E26"
Range("E28:I28") = "=D28 + 27"
End If
End Sub
Option Explicit
Sub Rebuild()
Dim cumtonnes As Long
'you initially had tonnes as the variable name, but I was not sure if this was a typo or not.
cumtonnes = Range("D28").Value
If cumtonnes > 2600000 Then
Range("E110:I120").Copy Range("F110:J120")
Range("D28").Copy Range("E28")
Else:
Range("E18:I28").Interior.Color = xlNone
Range("E18:I18") = ""
Range("E19:I19") = ""
Range("E20:I20") = 0
Range("E21:I21") = 2.4
Range("E22:I22") = "=E21+E20"
Range("E23:I23") = "=24 - E22"
Range("E24:I24") = "=100 * E23 / 24"
Range("E25:I25") = 3000
Range("E26:I26") = "=E25 * E23"
Range("E27:I27") = "=E26"
Range("E28:I28") = "=D28 + 27"
End If
End Sub
So I adjusted the part that will do the copy and paste of the cells. I did not add in any loop currently as I did not know what you wanted repeated 30 times.
Using a macro in excel 2007 I want to display the following errorbars:
No horizontal errorbar.
Red dashed with 100 plus value vertical errorbar.
I can get everything I want except the color and I don't understand why. Below is the code.
ActiveChart.SeriesCollection(6).HasErrorBars = True
With ActiveChart.SeriesCollection(6).ErrorBars
.EndStyle = xlNoCap
.Format.Line.Visible = msoTrue
.Format.Line.ForeColor.RGB = RGB(255, 0, 0)
.Format.Line.ForeColor.TintAndShade = 0
.Format.Line.Weight = 2
.Format.Line.DashStyle = msoLineDash
End With
ActiveChart.SeriesCollection(6).ErrorBar Direction:=xlX, Include:=xlNone, Type:=xlFixedValue, Amount:=0
ActiveChart.SeriesCollection(6).ErrorBar Direction:=xlY, Include:=xlPlusValues, Type:=xlFixedValue, Amount:=100
I ran into the same issue too. But after toggling the visible state of the error bars, the color change worked for me. Give this a try:
ActiveChart.SeriesCollection(6).HasErrorBars = True
With ActiveChart.SeriesCollection(6).ErrorBars
.EndStyle = xlNoCap
.Format.Line.Visible = msoTrue
.Format.Line.ForeColor.RGB = RGB(255, 0, 0)
.Format.Line.Visible = False 'ADDED
.Format.Line.Visible = True 'ADDED
.Format.Line.ForeColor.RGB = RGB(255, 0, 0) 'ADDED
.Format.Line.ForeColor.TintAndShade = 0
.Format.Line.Weight = 2
.Format.Line.DashStyle = msoLineDash
End With
Help please, below is my code in Visual Basic.
My for loop does not go to the second if condition. It just checks for the first one. What am I missing here?
Thanks!
If Not dsMarketingOrdIDs Is Nothing Then
For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
blnKbAuthorXtremeSupport = True
End If
If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
blnKbAuthorXtremePortal = True
End If
End If
End If
Next
End If
Should be something like that:
If Not dsMarketingOrdIDs Is Nothing Then
For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
blnKbAuthorXtremeSupport = True
End If
End If
If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
blnKbAuthorXtremePortal = True
End If
End If
Next
End If
Or even easier:
If Not dsMarketingOrdIDs Is Nothing Then
For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
blnKbAuthorXtremePortal = Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") _
AndAlso (dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 OrElse dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152)
Next
End If
Have you tried an else if?
If Not dsMarketingOrdIDs Is Nothing Then
For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
blnKbAuthorXtremeSupport = True
Else If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
blnKbAuthorXtremePortal = True
End If
End If
End If
Next
End If
Also, how can your MARKETING_ORG_ID be 5 and 152 at once??
dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5
dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152