how to rotate inlineshape?

shirazbj 2005-08-18 10:07:02
hi

I have a word document full of scaned photos.I want to rotate 180 degree for all the photos with VBA. But I couldn't find a rotate method for inlineshape. Here is the code. It rotate shapes with IncrementRotation method. But there is not that method for inlineshape. Should I convert inlineshape into shapes? I tried but could convert and then rotate just one.

Please help me sort it out. Thanks.

Sub FigureInfo()
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Dim sTemp As String

Set DocThis = ActiveDocument

iShapeCount = DocThis.Shapes.Count
MsgBox "iShapeCount=" + Str(iShapeCount)
If iShapeCount > 0 Then
End If
For J = 1 To iShapeCount
DocThis.Shapes(J).IncrementRotation 180
Next J

iILShapeCount = DocThis.InlineShapes.Count
MsgBox "iILShapeCount=" + Str(iILShapeCount)
If iILShapeCount > 0 Then
End If
For J = 1 To iILShapeCount
Next J

End Sub
...全文
244 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
shirazbj 2005-08-26
  • 打赏
  • 举报
回复
This IncrementRotation method should have no problem. I use it in my final solution.
xinliangyu 2005-08-25
  • 打赏
  • 举报
回复
按楼主所说就是某些机子上下面代码能正确地运行, 另一些则不能,Why?
For i = 1 To n
DocThis.Shapes.Range(i).IncrementRotation 180
Next i
shirazbj 2005-08-25
  • 打赏
  • 举报
回复
My final solution to my topic question

In my third post, I acclaimed that I have found the right answer. It works well with a sample document which has several pictures in one page. But when I changed to another computer and tried to work on my real document which was full of scanned pictures, each picture occupy one page, it failed, only the first picture worked well.
After some homework, I sort it out as this final Marco. It works perfect.

Sub MyRotateInlineShape()

Dim ishape As InlineShape
Dim myshape As Shape

Dim DocThis As Document

Set DocThis = ActiveDocument

'Convert inlineshapes into shapes
For Each ishape In DocThis.InlineShapes
ishape.Select
ishape.ConvertToShape
Next

n = DocThis.Shapes.Count
For i = 1 To n
DocThis.Shapes.Range(i).IncrementRotation 180
Next i

DocThis.Shapes.SelectAll
For Each myshape In DocThis.Shapes
myshape.ConvertToInlineShape
Next

DocThis.Save

MsgBox "Well Done."

End Sub
shirazbj 2005-08-25
  • 打赏
  • 举报
回复
Thank you for replying my post.

I should have read in my VBA book that it should begin from 1 in a FOR…NEXT loop to list the object, but I couldn’t find which page it is in. To address your concern, I tried some codes. Below is what I got.


To list each inlineshape in a For…Next loop, you should list from 0 to n-1. Try this Marco below. Both Method 1 and Method 2 work well.

Sub MyconvertToShape()

Dim myishape As InlineShape

Dim DocThis As Document

Set DocThis = ActiveDocument

'Method 1: Works well
'For Each myishape In DocThis.InlineShapes
' myishape.Select
' myishape.ConvertToShape
'Next

'Method 2: Works well
n = DocThis.InlineShapes.Count
For i = 0 To n - 1
DocThis.InlineShapes(i).Range.Select
DocThis.InlineShapes(i).ConvertToShape
Next i

DocThis.Save

MsgBox "Well Done."

End Sub

To list each shape in a FOR…Next loop, you must start from 1 to n. Try this Marco below. Both Method 1 and Method 2 work well. But Method 3 and Method 4 have problems.

Sub MyconvertToInlineShape()

Dim myshape As Shape

Dim DocThis As Document

Set DocThis = ActiveDocument

'Method 1: Works well
'DocThis.Shapes.SelectAll
'For Each myshape In DocThis.Shapes
' myshape.ConvertToInlineShape
'Next

'Method 2: Works well
For Each myshape In DocThis.Shapes
myshape.Select
myshape.ConvertToInlineShape
Next

'Method 3: With problem. Just 1st picture is ok
'n = DocThis.Shapes.Count
'DocThis.Shapes.SelectAll
'For i = 1 To n
' DocThis.Shapes(i).ConvertToInlineShape
'Next i

' Method 4: With problem. Just 1st picture is ok
'n = DocThis.Shapes.Count
'For i = 1 To n
' DocThis.Shapes(i).Select
' DocThis.Shapes(i).ConvertToInlineShape
'Next i

DocThis.Save

MsgBox "Well Done."

End Sub



Thank you for testing my marco.
shirazbj 2005-08-23
  • 打赏
  • 举报
回复
Yes, I am a chinese. But the computer I am using which has the internet connection only has a english system, so I couldn't input chinese.
No worry to fire chinese to me, i could read them on my screen.
xinliangyu 2005-08-23
  • 打赏
  • 举报
回复
我说的对不对呢?给回个话吧
xinliangyu 2005-08-23
  • 打赏
  • 举报
回复
原来如彼!
VBDN 2005-08-19
  • 打赏
  • 举报
回复
/关注/
xinliangyu 2005-08-19
  • 打赏
  • 举报
回复
shirazbj (),
Aren't you Chinese if you don't mind?
xinliangyu 2005-08-19
  • 打赏
  • 举报
回复
……
For J = 0 To iILShapeCount - 1
DocThis.InlineShapes(J).ConvertToShape
Next J
……

My experience show me that the INDEX of Word objects—here InLineShage—always start from 1 instead of zero,so above code should be run as following:

……
For J = 1 To iILShapeCount
DocThis.InlineShapes(J).ConvertToShape
Next J
……

shirazbj 2005-08-19
  • 打赏
  • 举报
回复
Finally got the right way.

For ... next is not good here.


Sub MyRotateInlineShape()


Dim ishape As InlineShape
Dim myshape As Shape

Dim DocThis As Document

Set DocThis = ActiveDocument

'Convert inlineshapes into shapes
For Each ishape In DocThis.InlineShapes
ishape.ConvertToShape
Next

'Rotate shapes
For Each myshape In DocThis.Shapes
myshape.IncrementRotation 180
Next

'Convert rotated shapes back to inlineshapes
For Each myshape In DocThis.Shapes
myshape.ConvertToInlineShape
Next

MsgBox "Well Done."

End Sub
shirazbj 2005-08-18
  • 打赏
  • 举报
回复
here is a revised version which added convert function. But still have problem.

In the code:
First convert inlineshape to shape, ok
then rotate, ok
finaly, convert rotated shape to inlineshape, NOT OK. Just the first is down. The error message says: The index into the specified collection is out of bounds.

Sub FigureInfo()
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Dim sTemp As String

Set DocThis = ActiveDocument

iILShapeCount = DocThis.InlineShapes.Count
'MsgBox "inLineShape Count=" + Str(iILShapeCount)
If iILShapeCount > 0 Then
For J = 0 To iILShapeCount - 1
DocThis.InlineShapes(J).ConvertToShape
Next J
End If

iShapeCount = DocThis.Shapes.Count
MsgBox "Shape Count=" + Str(iShapeCount)
If iShapeCount > 0 Then
For J = 1 To iShapeCount
DocThis.Shapes(J).IncrementRotation 180
MsgBox "Shape " + Str(J) + " has been rotated."
Next J

For J = 1 To iShapeCount
DocThis.Shapes(J).ConvertToInlineShape
MsgBox "Shape " + Str(J) + " has been converted into InlineShape."
Next J

End If

End Sub

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧