Hi guys!
I have a question. I would like to create a new excel workbook based on the information that I have in another workbook. I have created the code which asks to provide the range where the information is and then creates the new workbook, copies the information selected and creates a chart based on that information.
The code does not returns me an error, however it creates the wokbook without the information. I am posting my code, do you have any toughts how can I make this work?
I have a question. I would like to create a new excel workbook based on the information that I have in another workbook. I have created the code which asks to provide the range where the information is and then creates the new workbook, copies the information selected and creates a chart based on that information.
The code does not returns me an error, however it creates the wokbook without the information. I am posting my code, do you have any toughts how can I make this work?
Code:
Private Sub CommandButton1_Click()
Dim oRangeSelected As Range
On Error Resume Next
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"SelectARAnge Demo", Selection.Address, , , , , 8)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange = objWorksheet.UsedRange
objRange.Select
Set colCharts = objExcel.Charts
colCharts.Add
Set objChart = colCharts(1)
objChart.Activate
objChart.ChartType = 65
objChart.PlotArea.Fill.PresetGradient 1, 1, 7
objChart.SeriesCollection(1).Border.Weight = -4138
objChart.SeriesCollection(2).Border.Weight = -4138
objChart.SeriesCollection(3).Border.Weight = -4138
objChart.SeriesCollection(1).Border.ColorIndex = 2
objChart.SeriesCollection(1).MarkerBackgroundColorIndex = 2
objChart.SeriesCollection(2).MarkerForegroundColorIndex = 1
objChart.SeriesCollection(3).MarkerForegroundColorIndex = 1
objChart.HasTitle = True
objChart.ChartTitle.Text = ""
objChart.ChartTitle.Font.Size = 18
objChart.ChartArea.Fill.Visible = True
objChart.ChartArea.Fill.PresetTextured 15
objChart.ChartArea.Border.LineStyle = 1
objChart.HasLegend = True
objChart.Legend.Shadow = True
If oRangeSelected Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
Else
MsgBox "You selected: " & oRangeSelected.Address(External:=True)
End If
End Sub