Lock out macros and charts

supercrewed

Board Regular
Joined
Apr 9, 2010
Messages
86
I have a few questions, the first is; can I lock out the macros in a workbook, so they cannot be edited?
Next; Can I add the year only to a chart title, so it will change at years end to the New Year? I have the date created, but I’m lost as to the correct syntax, for the year only.
Lastly; I have created a sub to generate a chart, on an existing sheet, but I’m confused as to formatting it, in the following code what am I doing wrong. I'm using some code from the macro recorder, I edited / modified, and in the code below, how do I change the gridlines, back color, and so on?
Could someone point me in the right direction, Thanks…?

Sub AddChartObject()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
END_SELECT = 1<o:p></o:p>
<o:p> </o:p>
Dim myChtObj As ChartObject<o:p></o:p>
'************************************* SETS CHART, SHEET, RANGE, CHART TYPE ***********<o:p></o:p>
<o:p> </o:p>
Sheets("SUMMARY").Select<o:p></o:p>
ActiveSheet.Cells(2, 2).Select<o:p></o:p>
ActiveSheet.ChartObjects.Delete<o:p></o:p>
'*************************************SELECTS CELLS THAT ARE FILLED ********************<o:p></o:p>
Do<o:p></o:p>
If IsEmpty(ActiveCell) = False Then<o:p></o:p>
ActiveCell.Offset(1, 0).Select<o:p></o:p>
End If<o:p></o:p>
END_SELECT = END_SELECT + 1<o:p></o:p>
Loop Until IsEmpty(ActiveCell) = True<o:p></o:p>
<o:p> </o:p>
With NON_CONF_REPORT_FORM<o:p></o:p>
If .TOP_FIVE = True Then<o:p></o:p>
END_SELECT = 6<o:p></o:p>
ElseIf .TOP_TEN = True Then<o:p></o:p>
END_SELECT = 11<o:p></o:p>
Else<o:p></o:p>
END_SELECT = END_SELECT<o:p></o:p>
End If<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
'************************************* SETS CHART, SHEET, RANGE, CHART TYPE ***********<o:p></o:p>
Set myChtObj = ActiveSheet.ChartObjects.Add(Left:=330, Width:=650, Top:=10, Height:=385)<o:p></o:p>
With myChtObj.Chart<o:p></o:p>
<o:p></o:p>
.SetSourceData Source:=Sheets("SUMMARY").Range("B1:C" & CStr(END_SELECT)), PlotBy _<o:p></o:p>
:=xlColumns<o:p></o:p>
'.ChartType = xlBar 'xlLineMarkers<o:p></o:p>
.HasLegend = False<o:p></o:p>
.HasDataTable = False<o:p></o:p>
<o:p> </o:p>
'************************************* FORMATS CHART TITLE****************************<o:p></o:p>
<o:p> </o:p>
.ChartTitle.Caption = "REWORK / REMAKE TOTALS AS OF - " & FormatDateTime(Date, 2)<o:p></o:p>
.ChartTitle.Font.Size = 16<o:p></o:p>
.ChartTitle.Font.Name = "Times New Roman"<o:p></o:p>
.ChartTitle.Font.Bold = True<o:p></o:p>
<o:p> </o:p>
End With<o:p></o:p>
'**************************************** FORMATS Y AXES *****************************<o:p></o:p>
<o:p> </o:p>
With myChtObj.Chart.Axes(xlValue)<o:p></o:p>
.MinimumScaleIsAuto = True<o:p></o:p>
.MaximumScaleIsAuto = True<o:p></o:p>
.MinorUnitIsAuto = True<o:p></o:p>
.MajorUnitIsAuto = True<o:p></o:p>
.Crosses = xlAutomatic<o:p></o:p>
.ReversePlotOrder = False<o:p></o:p>
.ScaleType = xlLinear<o:p></o:p>
.DisplayUnit = xlNone<o:p></o:p>
.TickLabels.Orientation = 0<o:p></o:p>
<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
'**************************************** Y AXES *****************************<o:p></o:p>
With myChtObj.Chart.Axes(Type:=xlValue, AxisGroup:=xlPrimary)<o:p></o:p>
.HasTitle = True<o:p></o:p>
.AxisTitle.Characters.Text = "Dollars Lost"<o:p></o:p>
.AxisTitle.Font.Name = "Times New Roman"<o:p></o:p>
.AxisTitle.Font.Size = 14<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
'**************************************** X AXES *****************************<o:p></o:p>
<o:p></o:p>
With myChtObj.Chart.Axes(Type:=xlCategory, AxisGroup:=xlPrimary)<o:p></o:p>
.HasTitle = True<o:p></o:p>
.AxisTitle.Text = "Emplyees"<o:p></o:p>
.AxisTitle.Font.Name = "Times New Roman"<o:p></o:p>
.AxisTitle.Font.Size = 14<o:p></o:p>
.HasMajorGridlines = True<o:p></o:p>
.HasMinorGridlines = False<o:p></o:p>
.TickLabels.Orientation = 90<o:p></o:p>
<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
1) In the VB Editor use Tools | VBAProject... to add a password.

2) To get the year from a date use the YEAR function.

3) Use the macro recorder. Best way to get the necessary code. If you are using 2007 and do not get the code, chances are better (though no guarantee) that 2003 will give you the necessary code.
 
Upvote 0
Thanks as for the formatting, I've all but got it, just messing around, I'm beginning to understand it. I'll try the year function, can't be too difficult, Thanks for your help...
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,644
Members
449,461
Latest member
kokoanutt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top