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
...全文
155 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
发帖
VBA
创建于2007-09-28

2062

社区成员

VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
申请成为版主
帖子事件
创建了帖子
2005-08-18 10:07
社区公告
暂无公告