VBA Snippets
BoxInsert
Inserts a (1x1) table ready for a chart to be inserted.Public Sub Chart_BoxInsert(iNoOfCols As Integer, _
iNoOfRows As Integer, _
lChartHeight As Long, _
lLeftMargin As Long)
On Error GoTo AnError
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:="SEQ Figure", _
Preserveformatting:=True
.TypeText ": "
'Call Para_Select
.style = "Caption"
.TypeParagraph
.TypeParagraph
.MoveUp wdLine, 1
.Tables.Add Range:=Selection.Range, NumRows:=iNoOfRows, NumColumns:=iNoOfCols
.Rows.SpaceBetweenColumns = InchesToPoints(lLeftMargin)
' Call Table_BordersClear
' Call Table_BordersAdd(0)
'change all the formatting to zero paragraph spacings !!
.Tables(1).Rows(1).SetHeight rowheight:=12, _
HeightRule:=wdRowHeightAtLeast
'insert Figure ?? into cell (1,1)
.Tables(1).cell(1, 1).Select
.MoveDown wdLine, 1
.TypeText Text:="Source: "
' .style = sDEF_STYLE_TABLESOURCE 'define the style for the chart source
End With
If gbDEBUG = False Then Exit Sub
AnError:
Call Error_Handle("Chart_BoxInsert", msMODULENAME, 1, _
"insert a chart box at the current position")
End Sub
InsertFromFile
Inserts a chart from a file.Public Sub Chart_InsertFromFile(sFolderPath As String, _
sFileName As String, _
bLinkIt As Boolean)
On Error GoTo AnError
' On Error GoTo CannotInsert
' Selection.InlineShapes.AddPicture FileName:=gsDATASTREAMDIR & Directory & FileName, _
' LinkToFile:=LinkIt, SaveWithDocument:=True
Call Shape_Resize(150, 150)
CannotInsert:
If gbDEBUG = False Then Exit Sub
AnError:
Call Error_Handle("Chart_InsertFromFile", msMODULENAME, 1, _
"insert the chart """ & sFileName & """" & vbCrLf & _
"from the folder path" & vbCrLf & sFolderPath)
End Sub
Paste
Pastes the chart object from the clipboard to the current position.Public Sub Chart_Paste()
On Error GoTo AnError
Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
:=wdInLine, DisplayAsIcon:=False
'format appropriately
If gbDEBUG = False Then Exit Sub
AnError:
Call Error_Handle("Chart_Paste", msMODULENAME, 1, _
"paste the chart from the clipboard")
End Sub
PlaceHolderFormat
Format the place holder table that will contain a chart.Public Sub Chart_PlaceHolderFormat()
On Error GoTo AnError
If gbDEBUG = False Then Exit Sub
AnError:
Call Error_Handle("Chart_PlaceHolderFormat", msMODULENAME, 1, _
"")
End Sub
Size
Resizes a chart to a given size.Public Sub Chart_Size(sDSSize As String)
On Error GoTo AnError
Select Case sDSSize
Case "Margin": Call Shape_Resize(129, 129)
Case "Newsflow": Call Shape_Resize(150, 150)
Case "NmlWidth": Call Shape_Resize(200, 352)
Case "Company": Call Shape_Resize(200, 200)
Case "Chart x1": Call Shape_Resize(210, 210)
Case "Chart x2": Call Shape_Resize(130, 174)
Case "Custom 1": Call Shape_Resize(240, 240) 'Appendices
End Select
If gbDEBUG = False Then Exit Sub
AnError:
Call Error_Handle("Chart_Size", msMODULENAME, 1, _
"adjust the size of the chart / graph")
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top