Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

vba - Photo alignment in Excel after rotation in excel

I've got a macro where I would like to resize a photo and put it in a cell of my spreadsheet in Excel. I have the code figured out for how to get it to the right row and alignment it properly in the cell, unless I want to rotate the photo first - in which case the alignment is just wonky.

I tried setting the alignment of the picture to the cell and it doesn't work as it should, I've tried a flat correction to the alignment and a numerical correction based on picture height and they all place the picture offset of where they should be by ~20-25ish (the picture is too far right and too high for the correct cell), consistently. I've tried setting the alignment of the left side of the picture to the top of the cell as well to no effect.

I figure there are two likely solutions here (although I expect there are many more), I just don't know how to go about either of them:

  • Redefine what is ".Top" for the selection after rotation (allowing my alignment code to work properly)
  • Figure out where the offset issue is coming from so I can account for it in a consistent manner.

I've attached images of the offset that I'm talking about, along with the code that moved it there:

[Offset without a correction][1]

[Offset when setting selection top to cell left and vice versa][2]

[Correct alignment, but doesn't work for all images equally (when I have a different photo size, same issue as before on height)][3]

The issue is coming from these lines and it's driving me up the wall.

Does anyone have any ideas for how to go about this? Thank you for you time and attention, it is greatly appreciated! [1]: https://i.stack.imgur.com/Z9e6a.png [2]: https://i.stack.imgur.com/M1hYX.png [3]: https://i.stack.imgur.com/TChMV.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...