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")
Related
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.
I'm trying to use a macro in Word in order to adjust the width of a table. But I can't get it to work. When I use the SetWidth method on Selection.Columns in my macro, an error is thrown.
I use a macro that was working previously, but now it doesn't want to do this width adjustment. I already tried to use a variety of other solution like use width or preferredWidth instead of setWidth. I also tried executing that code earlier and it works fine.
This is the code supposed to adjust the column width.
Selection.GoTo what:=wdGoToBookmark, Name:="proj1_cat1_j"
Selection.Columns.SetWidth ColumnWidth:=105, RulerStyle:=wdAdjustFirstColumn
Moreover, the table is a big one. And I'm accessing the first cell of one column in order to adjust it. There is nothing that's attached to that table (like text on the right or something else)
The expected result is simply the table with the column adjusted. But instead I get an error code 4605 saying that I can't use the setWidth method because it's referencing the end of a table row.
Can anybody tell me what I am doing wrong ?
PS : I can't share more of the macro, it's so big it's difficult to know which parts are important to share or not.
I am hoping to get some help on a formula I've been banging my head against the wall over. Essentially I am using Concatenate to produce a formula, when this is then copied into the final cell, it won't execute. I've tried using the hidden Eval function but that doesn't work for this specific part, however, it does for the other. The only thing that seems to solve it is either pressing Enter on each cell, or using the Find/Replace function. However, I need this to happen automatically. I've recorded using Find/Replace without any luck. The displayed color aspect is a custom function that works perfectly. I have had to change some of the wording for sensitivity reasons.
Concatenate Part:
=CONCATENATE("=IF(DisplayedColor(",I3,")=38,",eval(I3)*100,",""",E3,")")
Result to Execute:
=IF(DisplayedColor('[Spreadsheet]Tab1'!$BV$19)=38,-6.43801947500129,"")
Use the Indirect Function as follows:
Formula = INDIRECT(CONCATENATE("=IF(DisplayedColor(",I3,")=38,",eval(I3)*100,",""",E3,")"))
The INDIRECT function is useful when you want to return a value, based on a text string.
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
In my program I want to add some values together with a running total, and then show that total in a text box. When I try to run it, though, it just shows zero.
Here's the code I'm using
TotalPrice = TotalPrice + Price
Next
TxtLuggage.Text = TotalPrice
this chunk was a part of a For next loop.
How do I fix this.
Please do not take this as an offense, but I think you should read some book or at least a decent article on .NET debugging. This one looks like an easy to spot with just a bit of basic debugging.
See this one for example, and pay special attention on stepping through code, setting breakpoints and watches
What you should do:
set a breakpoint in the code in the problematic code line
when debugger breaks code execution there, see which object are you changing the property for. Does this property change the text box text value? Are you using a correct form instance?
does the For..Next loop set it to zero on its final pass?