2017-12-19 5 views
0

Excel 워크 북에 새 차트를 만들고 플롯 영역의 치수를 다시 지정하려고했지만 코드가 작동하지 않는 것 같습니다. 어떤 도움이 필요합니까?Excel에서 차트의 플롯 영역을 어떻게 변경합니까?

 GlobVars.Wksht = GlobVars.Wkbk.Sheets(1) 'sets current working sheet as first sheet in wkbook 
    GlobVars.xlCharts = GlobVars.Wksht.ChartObjects 
    GlobVars.myChart = GlobVars.xlCharts.Add(30, 30, 800, 400) 'changes the starting location and height and width 
    GlobVars.chartPage = GlobVars.myChart.Chart 

    GlobVars.chartPage = GlobVars.myChart.Chart 
    GlobVars.chartPage.ChartType = Excel.XlChartType.xlXYScatter 'changes chart type 
    GlobVars.chartPage.PlotArea.Width = 600 
    GlobVars.chartPage.PlotArea.Height = 300 

마지막 두 줄은 내가 작업하려고하는 줄입니다. 어떤 도움이라도 대단히 감사합니다.

+0

당신이 무엇을 실행할 발생하면? 오류가 있습니까? –

+0

'AutoLayout'과'uniformaxis'를'false'로 설정 했습니까 ?? –

답변

0

나는 그것을 이해하고, 내 차트 영역을 내 실제 차트 개체로 설정하지 않았으므로 null 값 오류 예외가 발생했습니다.

여기에 내 코드 비트는 내가 가지고있다 :

Dim chartPage As Excel.Chart 
     Dim xlCharts As Excel.ChartObjects 
     Dim myChart As Excel.ChartObject 
     Dim chartRange As Excel.Range 

     GlobVars.Wksht = GlobVars.Wkbk.Sheets(1) 'sets current active sheet 
     GlobVars.Wksht.Activate() 
     xlCharts = GlobVars.Wksht.ChartObjects 
     myChart = xlCharts.Add(30, 30, 800, 600) 'changes chart height, width, and starting corner 
     chartPage = myChart.Chart 'assign "chartPage" to myChart (this was my error before) 
     chartPage.PlotArea.Width = 500 
     chartPage.PlotArea.Height = 600 
     chartPage.ChartType = Excel.XlChartType.xlXYScatter 'changes chart type 
0

이 개념을 사용하여 마지막으로 사용한 행 및 마지막으로 사용한 열을 찾는 방법은 어떻습니까?

Dim lRow As Long 
Dim lCol As Long 

    'Find the last non-blank cell in column A(1) 
    lRow = Cells(Rows.Count, 1).End(xlUp).Row 

    'Find the last non-blank cell in row 1 
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column 

또한 개체를 반복하여 차트를 찾고 차트에 이름을 지정하십시오.

Dim sht As Worksheet 
Dim CurrentSheet As Worksheet 
Dim cht As ChartObject 

Application.ScreenUpdating = False 
Application.EnableEvents = False 

Set CurrentSheet = ActiveSheet 

For Each sht In ActiveWorkbook.Worksheets 
    For Each cht In sht.ChartObjects 
    cht.Activate 

    'Do something with the chart... 

    Next cht 
Next sht 

차트 개체를 식별하고 선택한 후에 변경 작업을 수행하는 것이 좋습니다. 온라인에서 샘플 코드를 찾거나 단순히 매크로를 기록하고 수행해야 할 단계를 클릭하십시오. 위의 예제에서 파생 된 이름으로 일반 'chart1', 'chart2', 'chart3'등을 업데이트하십시오. 기록 된 매크로 코드를 여기에 게시 한 코드와 혼합하면 비즈니스를 수행 할 수 있습니다.