Lost lines when transfer text from a table to a shape in PowerPoint - vba

I have been working on a PowerPoint presentation for a game show at my high school. I tried to import questions from a PowerPoint table like this:
using the code as follows:
Slide1.Shapes("question").TextFrame.TextRange.Text = ActivePresentation.Slides(6).Shapes(1).Table.Cell(k + x, 3).Shape.TextFrame.TextRange.Text
Slide1.Shapes("answer").TextFrame.TextRange.Text = ActivePresentation.Slides(6).Shapes(1).Table.Cell(k + x, 4).Shape.TextFrame.TextRange.Text
with k and x being variables for my question number calculating method (which is not related to the problem).
The problem that I encounter is some of the text transferred are missing while the code is running, for example:
This occasionally happens from time to time, with the text only appearing a few beginning lines and the rest are not shown.
When I escaped the slide show and then show it again (without the code running and the data is still there), the text appears just fine:
Even when the code is running and the error occurs on the slide show, when I Alt+Tab to see the editor window the text is still there fully.
I couldn't figure out anything for days now. Please help me, I'd be very grateful if you did so.

Related

Table (Shape) Insert and Resize/Reposition in Powerpoint keeps repositioning

I wrote a function that copies a range/table from Excel, pastes it into a PowerPoint Slide and changes size and position. The code works as expected when executed alone, but not so when executed in a series of function calls.
In those cases the size is kept as changed but the shape/table is moved to another position. It seems the scaling is changed later on, but I don't know why. The new table can be seen at its correct position in the slide thumbnail in the left overview, but not so in the slide itself. (edit: This changes after a few second when opening the slide. Which means at some point during the code execution the shape was at the correct position.) I put a debut.print before and after the two parameters left and top to see what happens.
Left (debug.pring after insert): 48 (error!!)
Left (debug.print after change): 48.02496 (as coded/wanted)
Left (after whole macro finished): 384.025 (as later read out by immediate)
The issue seem to be with the scaling of the first two read outs. When I run the function without repositioning. The position it is inserted at is 384... and when changed to 48... it looks as expected. But in my case, what should be 384... is at the moment of insert 48. When changed to 48..., the shape is of course only moved a tiny bit. But then the whole slide seems to be rescoped and suddenly what used to be 48... is then 384..., instead of being 384... in the first place.
How is that possible? How can I counter it?
I don't even know what error to google for, since this seems so random.

Add text box at specific location in report base on value

I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated.
Thanks,
Dave
I played around with the monospace font idea. It isn't as pretty as I would like but I'm getting closer.
The issue is that I cannot keep the text in the same spot in each box. There is one line lower on the page that pushes the number almost out the right side of the box.
Sample Output
This code is functional but I'm looking at the cosmetics. I'm inserting spaces between my values using the following function:
Private Function InsertSpaces(CutLen, PieceLen) As String
MaxChar = 50 ' 6 inch 14pt Courier text box
cutchar = Int(CutLen / PieceLen * MaxChar)
Cutcharcount = Len(Str(CutLen))
cutchar = cutchar - Cutcharcount + 1
For i = 1 To cutchar
InsertSpaces = InsertSpaces + " "
Next
End Function
I'm just trying to clean it up. CreateReportControl was giving me a error because I wasn't in design mode. I'm guessing that is because it ran as part of OnFormat of the Detail section.

VBA ShapeRange.Rotation Property randomly stops working

I am trying to rotate a shape. Below is the relevant snippet.
Sheets("Sheet1").Shapes.Range(Array("Down Arrow 8")).Select
Selection.ShapeRange.Rotation = 90 + Sheets("Sheet2").Range("H8")
My problem is that the last line randomly works and randomly doesn't! I used to have it as a number (instead of a to string) but this refuses to work! It worked fine, then I made some changes to the macro and then it helpfully returned Error 438 - Object doesn't support this property or method. I fiddled around, debugged, etc (without ever changing the code) and it started working! Then I made some more changes and it stopped working and it seems to have stopped working for good. I literally copied this code from a recorded macro.
What I have tried:
Using CStr() to convert the value to a string
Declaring a variable and using the variable
What I really don't understand is why it would work without me changing the code and them stop working without me changing the code (i.e. the relevant lines)
A few things. First, avoid select. It isn't necessary and will save you a lot of headache and time in the future. Second, you can reference the shape by its name right from the Shapes object, assuming you are only intending to rotate one shape with the code. Finally, are you certain the value in Sheets("Sheet2").Range("H8") is numeric? If not, this could cause an error. The code below handles the first two issues. Beyond that, we'll need to see more code to determine the error.
Sheets("Sheet1").Shapes("Down Arrow 8").Rotation = 90 + Sheets("Sheet2").Range("H8")

VBA Macro 'Moving" Graphics / Dynamic Graphs

Basically, the problem here is that I have a macro which changes the number of a specific cell and by doing that I change the numbers from three columns and when those numbers are changed my graphic starts to 'move'.
To be more specific, I have this graphic:
When I click on the button I have, the lines starts to move, and it looks like a mouth opening and closing.
The blue line corresponds to the first and second column values, whereas the red line is changed accordingly to the first and third column values:
Cell(B2) contains the number generated by this code:
Sub OpenMouth()
For i = 1 To 20
Worksheets("Mouth").Cells(2, 2).Value = 0.1 + 2 * i / 20
Calculate
For j = 1 To 5000000
Next j
Next i
End Sub
What I need to do is to prepare something similar: A graphic that by changing the numbers I have in columns A, B and C, it starts to move. The columns A, B and C will be changed by doing a simple loop in VBA, this loop will change one value, and the three columns will have a formula linked to this value, so they will have their values changed.
I've seen some really cool graphics, a ball rolling, a wheel moving, but I really don't have a clue of how to do this, I don't know how to do it.
Does anyone have an idea? Can anyone help me build a different graphic with a similar idea (of an object moving)?
This is another example, using the same logic:
Frankly, I would suggest rethinking your approach of creating a custom & complex animation in Excel. Excel just isn't the right tool for this.
I would use Javascript and embed a Internet Explorer control into Excel with the animation. The solution would work as follows:
Press a button in Excel
A VBA macro executes the animation by loading the Microsoft Web Browser control with a custom HTML file with your animation in Javascript. The animation is show in the MS Web Browser Control.
Drawing in Javascript
Here a simple tutorial:
http://www.w3schools.com/html/html5_canvas.asp
Test your drawings here:
http://www.codecademy.com/courses/web-beginner-en-SWM11/0/1
Microsoft Web Browser Control
https://msdn.microsoft.com/en-us/library/aa752040(v=vs.85).aspx

VBA Code quit working in Word 2010

I don't know why, but this code has suddenly stopped working and I am looking for help in finding the reason why.
PictCount = ActiveDocument.Shapes.Count ' This always returns 0
PageCount = ActiveDocument.ActiveWindow.Panes(1).Pages.Count ' This gives the correct number
This is on a page that several pictures have been copied/pasted onto.
A picture is not seen as a shape when it is inlined with the text. If it floats over, underneath or between the text, then it is counted as a shape. So, right-click the picture, choose 'Wrap text', and then any other option than 'Inline with text', and you should see the number increasing.
As a counterpart, there's also InlineShapes, which contains those inlined pictures, and not the floating pictures.
So adding them up should give you all pictures together.
PictCount = ActiveDocument.Shapes.Count + ActiveDocument.InlineShapes.Count