Set SmartArt text when slideshow is active - vba

Using PowerPoint 2016, I am writing a macro that allows the user to input data in a live presentation using UserForms and TextBoxes. This is working nicely, except when i try to display the text in a SmartArt. The following macro illustrates the problem:
Sub writeToSmartArt()
Dim artShape As Shape
Set artShape = ActivePresentation.Slides(maalSlide).Shapes("Diagram")
MsgBox artShape.SmartArt.Nodes(1).Nodes(1).TextFrame2.TextRange.Text
artShape.SmartArt.Nodes(1).Nodes(1).TextFrame2.TextRange.Text = "testing"
End Sub
The sub sets the SmartArt shape to the artShape variable, and first prints out the contents of a specified node in a MsgBox. In the next step, I am setting the text property to a new value. Everything works fine as long as the presentation is not active. I am able to manually run the sub, and everything behaves as expected. However, when the slideshow is running i get the following error message when trying to write to the SmartArt node:
Run-time error '-2147467259 (80004005)':
Method 'Text' of object 'TextRange2' failed
Displaying the current content in the MsgBox still works. How can i overcome this problem?

Not sure why you get an error in slideshow mode. However, a workaround would be to use the node's Shape() method to access the shape directly, instead of the node itself, like so: artShape.SmartArt.Nodes(1).Nodes(1).Shapes(1).TextFrame2.TextRange.Text = "testing". Hope this helps!

I had the same problem, so instead use SmartArt.Nodes(), I am using SmartArt.AllNodes().
Exemple:
ppt_output.Slides(SLIDESMART).Shapes("TheList").SmartArt.AllNodes(1).Shapes.TextFrame2.TextRange.Text

Related

Error using built-in dialog box "xldialogApplyNames"

I wanted to use the named built-in dialog box in Excel via VBA. I learned to use it like this here.
That is working for many named built-in boxes, but not for ApplyNames. All arguments are optional, so that is not the problem. I also tried to define a boolean variable and say variable = dialogbox so that the box (outcome is a boolean as far as I understood it) has something to write the result in. But that didn't work either.
My code looks like this:
Public Sub Box()
Application.Dialogs(xlDialogApplyNames).Show
End Sub
The error which occurs is:
Laufzeitfehler 1004: Objekt- oder Anwendungsdefinierter Fehler"
or in english (hope I translated it correctly):
"runtime error 1004: error of object or application"
Thank you in advance!
Simon
I just tested and I can reproduce the error if the active workbook does not contain any range names. As soon as you add one the dialog is displayed. So:
Public Sub Box()
If ActiveWorkbook.Names.Count >0 Then
Application.Dialogs(xlDialogApplyNames).Show
End If
End Sub

invalid outside procedure Error In Access?? Looked at other questions on this site but still do not understand

My code in vba for access was working fine, I had procedures that I wrote for different events that all worked. Then when I went to give my combo boxes and text boxes an assigned row source and now nothing works. I get this invalid outside procedure error. So after hours of trouble shooting I ended up deleting the entire form and then rebuilding it and I still get the same error. So now I just working with one event just until I can get things figured out.
Public Sub cb_op1_AfterUpdate()
tb_LbrRate1.Value = DLookup("LaborRate", "tbloperationsType", "[operationsID] = cb_op1.value")
End Sub
This use to work but now it won't?? tb_LbrRate1.value is a text box and cb_op1.value is a combo box.
I have tried this too
Public Sub cb_op1_AfterUpdate()
End Sub
I left everything blank and I still get the error when I change a value in my combo box?? I just don't get it!!!! any help would be appreciated.
Can you do this:
and check what you get?
This error in MS Access is usually because of code flying not between Sub and End Sub.

How to check if clipboard is empty of text?

If I try to paste from an empty clipboard, I get an error. I would like to check if the clipboard is empty of text before pasting so that I can avoid this. How can this be accomplished? I'm aware it can be done through error handling, but I would prefer a method that avoids an error.
Edit -- Per request, adding code that creates the error and the error message:
Code that causes the problem:
Sub PasteFromEmptyClipBoard()
Selection.Paste
End Sub
Error message that I get:
"Run-time error '4605' This method or property is not available because the Clipboard is empty or is not valid."
Very important: You must first set a reference to the "Microsoft Forms 2.0 Object Library" (as in the attached screenshot below) before implementing this code. You may find that it is not an option when you scroll through the reference libraries. To make it show up, just add a form to the project (you can always delete the form later).
Sub CheckClipboard()
Dim myDataObject As DataObject
Set myDataObject = New DataObject
myDataObject.GetFromClipboard
If myDataObject.GetFormat(1) = True Then
'''There is text on clipboard, so it's safe to paste
Else
'''there is no text on the clipboard, so you may get error.
End If
End Sub

Programming VBA in an Outlook form

I created my own Outlook form to use it as standard surface to enter certain orders instead of the normal message form. The creation, editing and sending works perfectly fine and in the next step I want to insert some code via VBA.
My problem is that I can´t access the objects of my form in the VBA editor. E.g. I want to show a message box when a certain checkbox is checked. According code would be:
Sub example()
If CheckBox1.Value = True Then
MsgBox("Checkbox 1 is checked.")
End If
End Sub
When I run the code I get the error that the object could not be found. The same goes for every other object, like textboxes or labels etc.
I guess the solution is pretty simple, like putting Item. or sth. like that in front of each object. But so far I wasn't able to find the solution.
I´m using Outlook 2010.
I know this is a year too late but you'll want to do something like this example below. It's kinda a work around but you can get whatever value was selected.
Sub ComboBox1_Click()
Set objPage = Item.GetInspector.ModifiedFormPages("Message")
Set Control = objPage.Controls("ComboBox1")
MsgBox "The value in the " & Control.Name & _
"control has changed to " & Control.Value & "."
End Sub
You should be able to get the value, just get a handle on the object you want using the Inspector
The following is an excerpt from here
When you use a custom form, Outlook only supports the Click event for
controls. This is a natural choice for buttons but not optimal for
controls like the combo box. You write the code by inserting it into a
form’s VBScript editor. You need to have the Outlook form open in the
Form Designer and click the View Code button found in the Form group
of the Developer tab.
Sub CheckBox1_Click()
msgbox "Hello World"
End Sub
The code page is fairly minimal with no syntax highlighting. I just tried this now and it does work. Dont forget to Publish your form to pick up the new changes.
I know this is almost 6 years late but, in VB and VBA, simply start with the form name. (And if that doesn't work, just keep going up a parent object and you'll get there.) So, your code becomes:
Sub example()
If MYFORMNAME.CheckBox1.Value = True Then
MsgBox("Checkbox 1 is checked.")
End If
End Sub
Of course, after typing "MYFORMNAME." you'll know if it will work because typomatic will kick in when the system recognizes "MYFORMNAME" after you hit the period.

Error on ActiveSelection.Tasks

Does anyone know what this means
Set oProjTasks = ActiveSelection.Tasks
I have a macro that generates status reports from MS project and exports them directly into MS Word. It is a slick tool when it works.
When I run it now it throws "runtime error '424': object required" at this point.
How do I fix this?
The code that you are displaying is a set statement, that is setting the object ProjTasks equal to the task that is selected in the message box. The ActiveSelection property returns a selection object that represents the active selection.
It could be that you are experiencing an issue where there are no items selected, in which case it will throw a trappable error code 424. There is a code snippet that you can modify from the MSDN that will work to prevent this type of error from occuring.
Here is the link to the MSDN article... just remember to not use this code verbatim, but modify it to work with your macro.
http://msdn.microsoft.com/en-us/library/aa169315%28v=office.11%29.aspx
You could try just wrapping the error check around the set statement. I've written a small macro on a non-empty project file:
Sub Testing()
On Error GoTo ActiveSelectionErrHandler:
Set oProjTasks = ActiveSelection.Tasks
If oProjTasks Is Nothing Then
MsgBox "No tasks in current project"
End If
ActiveSelectionErrHandler:
Set oProjTasks = ThisProject.Tasks 'or something like that
Resume Next
End Sub
This handles the error but as Steve has already expressed more work is required to integrate the code.
You will have to follow the code to make changes to handle oProjTasks being empty where it is expected to have some values. Otherwise you will see more errors perhaps where the oProjTasks is found to be empty.
Another alternative solution could be to launch the macro after selecting a project as the code you have quoted will work fine if something is selected.