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

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.

Related

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

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.

Pictures do not go to their designated spots when copied to canvas

Link to code
I am attempting to move 5, individual pictures (as defined at the beginning of the code) and manipulate each picture in a different way. Each function that is used to manipulate a picture has a pretty obvious name for what is going to happen to that picture
I am using Jes to code this in Jython.
My problem is that even though I clearly specify where on my final canvas that I want these pictures to go to, they for some reason all default to (0, 0). So basically, the only picture that will be displayed is whichever the last one is that is called on. If you were to comment out the last picture, which in the code is the fifth (the "lighten" one), the fourth picture would be the one that got displayed instead so this proves that the pictures are all defaulting to (0, 0). The pictures do not go to their designated spots and that is what I am having trouble with.
***Side note: the functions "greyScale", "colorAvg", "colorSwap", and "lighten" should have nothing to do with the problem. I also don't think my "copy" function should be a problem either but I could be wrong.
I changed my copy function so that the parameters are (picture, destination, targX, targY)
Then in the copy function I made it:
targetX = targX
and then later
targetY = targY

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")

Formatting Marks also show and hides tables

I have a weird bug.
The below report is built from from a complex Excel Macro and below is a single page from the report output. The page is built from a range so the report is all in tables which is fine.
https://drive.google.com/folderview?id=0B-A_d72xVQXtfmVQUFFHdmVvUUdldUpLT1dmRnk4bXowaDNtUWt0eE5yeE1mZHRKNEpyck0&usp=sharing
The problem I am having is that the table Excel has put into this particular page (and about 1-2 others), is that the "show/hide formatting marks" button (e.g. the backwards P at the top of word) also show and hides the table and anything in the table.
I can expand on this as much as needed and have provided a download link as the only way to really show it is for it to be seen by turning the formatting marks on and off. I have removed text on that sheet as some of it is sensitive.
Excel code being used to copy and paste is below. This code works fine for the other 100-200 pages.
Sheets(curr_sheet).Range(sp(0), sp(1)).Copy
oDoc.ActiveWindow.Selection.Paste
any ideas?
I have found the answer thanks to #Tim Williams pointing me in the right direction.
It was because of the hidden text flag being set to true, I do not know how it got set to true as I can not find any reason for it to be.
Anyway if anyone else is looking this sloved my problem
oDoc.ActiveWindow.Selection.WholeStory'select everything
oDoc.ActiveWindow.Selection.Font.Hidden = False'Turn hidden off for whole document

Hiding Page Breaks in Excel

Following on from my previous questions:
I have implemented a series of checkboxes with which users can hide/unhide ranges of data. This is great - it works. The problem is when the users go to print - the hidden data is hidden but the pages are still there but blank.
If the page breaks are left to their own devices then everything is fine - there are no blank sections. When manual page breaks are used then you can see where the data was.
I've tried everything to get rid of the blank areas.
Copying the ranges and recalculating the page breaks is a no-go as the page breaks take upwards of 2 minutes for a fairly small report.
So, how can I print only the ranges that aren't hidden?
Thanks, G.
Haven't tested it, but you could change the print range to only the visible cells:
Public Sub SetPrintRangeToVisible(ByRef ws As Excel.Worksheet)
ws.PageSetup.PrintArea = ws.UsedRange.SpecialCells(xlCellTypeVisible).Address
End Sub
Excel, by default prints only visible cells. You wouldnt have to set the Print area to visible cells as previously suggested.
I suppose you have un-checked the Print Object option in all of the Check-boxes. And that area appears blank, when you print the sheet. If that is the case, read on:
I suggest writing a simple macro that hides the rows that contain the check boxes. Set the visible property of the check boxes to false. Print the sheet, and then return everything back to the original state.
Alternatively, you could just select the rows above the check boxes, then the entire area below the check boxes, and then set that as the PrintArea. That should solve the problem you are having.
Also, I may have wildly misunderstood the situation, in which case, I am sorry I wasted your time.