ฉันใช้ VBScript เพื่อสร้างพล็อตกระจายเส้นจากคอลัมน์ข้อมูลใน Excel 2003 ซึ่งออกมาดีแล้ว แต่ฉันต้องการแก้ไขคุณสมบัติบางอย่างของแผนภูมิ เช่น สีพื้นหลังและป้ายกำกับแกน ฉันทำสิ่งนี้ด้วยตนเองใน Excel และบันทึกแมโคร ซึ่งให้โค้ด VBA ต่อไปนี้แก่ฉัน:
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.ReadingOrder = xlContext
.Orientation = 45
End With
ActiveChart.Axes(xlValue).AxisTitle.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Orientation = xlHorizontal
End With
ActiveChart.ChartArea.Select
End Sub
นี่ดูดีสำหรับ VBA แต่ฉันมีปัญหาในการแปลงเป็น VBScript ฉันควรเริ่มต้นอย่างไร? นี่คือรหัสของฉันในขณะนี้:
Set objChart = objExcel.Charts.Add()
With objExcel.ActiveChart
.ChartType = xlXYScatterLinesNoMarkers
.SeriesCollection(1).Interior.Color = RGB(255, 0, 0)
.HasTitle = True
.ChartTitle.Text = "usage"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "units"
.HasLegend = False
.SetSourceData objWorksheet.Range("E1","F" & LastRow), xlColumns
.SetSourceData objWorksheet.Range("E1:F200"), xlColumns
End With
บรรทัด .SeriesCollection(1).Interior.Color = RGB(255, 0, 0) ทำให้เกิดข้อผิดพลาด: "ไม่สามารถตั้งค่าคุณสมบัติสีของคลาส Interior" ฉันเดาว่าฉันไม่ควรเรียก .SeriesCollection ใต้ .Activechart มีข้อเสนอแนะอะไรบ้าง? ณ จุดนี้ ฉันยินดีเป็นอย่างยิ่งที่สามารถเปลี่ยนสีพื้นหลังของแผนภูมิเป็นสีขาว และหมุนป้ายกำกับแกน x 45 องศา
ขอบคุณล่วงหน้า.
xlCategory
ได้: Excel VBA รู้ว่าค่าเหล่านั้นคืออะไร แต่ไม่มีใน VBScript คุณสามารถค้นหาค่าตัวเลขได้ใน Object Browser (F2 ใน VBEditor) - person Tim Williams   schedule 17.07.2013?xlCategory
แล้วกด Enter ในหน้าต่างทันที - person Jon Peltier   schedule 20.08.2015