Hi All,
I am developing one application in VBScript which automatically generates excel charts. But, I have a problem here.
I need to get the range value(like A1:B50) before calling the Activechart.setSourcedata function.....
In the below code I am asking the user to enter the range.
But, It is not requiremnet, The user just gives the .xls file. We need to get the range of the data.
Please give me the code which gets the range of an excel sheet.
thanx in advance....................
------------------------------VBCode--------------------
AutoChart()
sub AutoChart()
dim app, chartType
set app = createobject("Excel.Application")
'Make it visible
app.Visible = true
'Ask for file name
sFilename = app.GetOpenFilename("All files (*.*), *.*")
'To Exit if Cancel was pressed
If sFilename = "False" Then Exit Sub
' Add a new workbook
dim wb
set wb = app.workbooks.open(sFilename)
'Read the range
Dim inRng
inRng = InputBox("Enter the Range ( Ex: A1:F50 )", "Range")
'Get the range
dim rng
set rng = wb.ActiveSheet.Range(inRng)
'Add a new chart
wb.Charts.Add
'Assgin the chart type
wb.ActiveChart.ChartType = 65
'Set the SourceData
wb.ActiveChart.SetSourceData rng, 2
' Give the user control of Excel
app.UserControl = true
end sub
-----------------------------end----------------------------