I have a chart that I modify with VBA by changing the values from an excel-workbook. Everything works fine, but I want to use the treemap-chart where suddenly the code stops working.
The code works perfectly fine with the other charts in PowerPoint but when I change it to TreeMap the Code stops executing and the chart doesn't change it values.
Option Explicit
Sub Chart_TT()
With ActivePresentation.Slides(2).Shapes("Chart 1").Chart.ChartData
.Activate
.Workbook.Sheets(2).Range("C2").Value = .Workbook.Sheets(2).Range("I9").Value
.Workbook.Sheets(2).Range("D2").Value = .Workbook.Sheets(2).Range("J9").Value
.Workbook.Sheets(2).Range("E2").Value = .Workbook.Sheets(2).Range("K9").Value
.Workbook.Sheets(2).Range("F2").Value = .Workbook.Sheets(2).Range("L9").Value
.Workbook.Close SaveChanges:=True
End With
End Sub
The error code which is shown is:
"Error -2147467259 (80004005): The method "workbook" for the object "ChartData" failed.
What do I have to change that the code also works with the TreeMap chart?
Thanks!
Sorry, the treemap chart style is fairly new and has not been included in the VBA object model.
Related
I added a chart using this piece of code:
ActiveSheet.Shapes.AddChart2(419, xlFunnel).Select
Now, I wish I could select this graph, so that I can rename it.
PS: What does it mean AddChart2? Is this standard code or not?
Here you go!
Dim MyChart As Shape
Set MyChart = ActiveSheet.Shapes.AddChart2(419, xlFunnel)
MyChart.Chart.SetSourceData Source:=Range("Sheet1!$F$2:$F$4")
MyChart.Name = "My new chart"
Regarding the AddChart vs AddChart2 question - read more here What does the number in the AddChart2 VBA macro represents?
I use Excel 2016
I want to add a page to a Multi Page control.
For some reason I get the error "Run-time error '13': Type mismatch"
I have a blank Excel file with a UserForm. On the UserForm I have a CommandButton and a MultiPage, both are out of the box. I added the following code to the CommandButton
Private Sub CommandButton1_Click()
Dim myPage As Page
Set myPage = Me.MultiPage1.Pages.Add("testpage", "TestPage")
End Sub
Do I need to add references to some toolkit for this to work? For the moment I have the following references active
Visual Basic For Applications
Microsfot Excel 16.0 Object Library
OLE Automation
Microsoft Office 16.0 Object Library
Microsoft Forms 2.0 Object Library
When I write the Dim myPage declaration I get a list of objects.. I have two Page objects? Also when I write
myPage.
to get a list of available things for that object I see the following
CenterFooter
CenterHeader
LeftFooter
LeftHeader
RightFooter
RightHeader
So I assume myPage object is not from the right Page type
This works also:
MultiPage1.Pages.Add "tst1", "TestPage"
This works without getting a reference to the new Page object
Me.MultiPage1.Pages.Add
Me.MultiPage1.Pages(Me.MultiPage1.Pages.Count - 1).Name = "testpage"
Me.MultiPage1.Pages(Me.MultiPage1.Pages.Count - 1).Caption = "TestPage"
Debug.Print Me.MultiPage1.Pages(Me.MultiPage1.Pages.Count - 1).Name
Debug.Print Me.MultiPage1.Pages(Me.MultiPage1.Pages.Count - 1).Caption
The easy non code way:
Left click->New Page
I have a Userform and this is the code for my control button. Trying to pass a Textbox to a function using the following code
Private Sub pdclear_Click()
Dim textinput As TextBox
Set textinput = frmBigInputBox
Call clear(textinput)
End Sub
The line highlighted yellow in debug mode is
Set textinput = frmBigInputBox
Why does this cause a "13 type mismatch" error??? What am I doing wrongly?
Try using MSForms.TextBox. As in
Dim textinput As MSForms.TextBox
Works for me.
I could reproduce the error and found this: http://forums.devx.com/showthread.php?168758-Excel-VBA-Using-TypeOf
So you will have to define it as MSForms.TextBox, it seems.
I am hoping to set all of the togglebuttons in a powerpoint to "false" (unpressed) upon starting the program. Any ideas why this sort of code is working?
Sub Start()
ActivePresentation.Slides(4).ToggleButton1.Value = 0
ActivePresentation.Slides(4).ToggleButton4.Value = 0
ActivePresentation.SlideShowWindow.View.Next
End Sub
Thank you!
The syntax
ActivePresentation.Slides(4).ToggleButton1.Value = 0
is correct; I've just tested it and it works.
Are you actually calling the Sub at any point though? Simply naming it Start() is not enough.
Related question re. running code on startup, could be helpful.
I had an issue calling this
ActivePresentation.Slides(4).ToggleButton1.Value = 0
Getting the error Method or data member not found which im assuming is a scope issue. The VBA editor doesnt autocomplete .ToggleButton1 which supports the error i was getting.
So, it appears im referencing the object incorrectly.
To correct this I have done the following.
Public Sub ToggleThisButton()
' This is code on Slide 1 referencing control on slide 4
ActivePresentation.Slides(4).Shapes("ToggleButton1").OLEFormat.Object.Value = 1
End Sub
Excerpt from MSDN
Use the OLEFormat property for a shape, inline shape, or field to
return the OLEFormat object. The following example displays the class
type for the first shape on the active document.
Use the Object
property to return an object that represents an ActiveX control or OLE
object. With this object, you can use the properties and methods of
the container application or the ActiveX control.
Got a trouble in a VBA excel program.
Sub code(s)
...
code = t
End Sub
And then :
Sub CommandButton1_Click()
...
For i = 0 To size
current_y = code(string_array(i))
...
End Sub
When i run the program, i got this error "Variables are required" (not sure, i'm working on a japanese version of excel). Sub CommandButton1_Click is highlighted and code is selected inside CommandButton1_Click. Can't figure out why, though it must be simple...
You're trying to return a result from a Sub. Try declaring it as a function instead, as this is able to return values to the caller:
Function code(s)
...
code = t
End Function
If it makes it any clearer, on my English version the error message is:
Expected Function or variable
Does the code include Option Explicit? Perhaps the error translates to "Variable declaration required"? Try removing option explicit - if that fixes it remove that line, then go through checking all variables are declare (e.g. dim current_y as string).