Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2020, 12:18 AM
tyxanu tyxanu is offline VBA to rotate images by selection or another condition? Windows 8 VBA to rotate images by selection or another condition? Office 2013
Novice
VBA to rotate images by selection or another condition?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default VBA to rotate images by selection or another condition?

Hello again,



I am facing with another tedious situation in MS Word daily, based on the sample below.

How can I batch rotate multiple images that are left/right oriented in my table? (Assuming I have no control over the original extraction method of the images into the table).

Thanks!
Attached Files
File Type: docx testt.docx (107.5 KB, 8 views)
Reply With Quote
  #2  
Old 09-07-2020, 02:14 AM
gmayor's Avatar
gmayor gmayor is offline VBA to rotate images by selection or another condition? Windows 10 VBA to rotate images by selection or another condition? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Based on your example I suspect you want


Code:
Sub Macro1()
Dim ocell As Cell
Dim oInlineShape As InlineShape
Dim oShape As Shape
    Set ocell = ActiveDocument.Tables(1).Cell(1, 1)
    Set oInlineShape = ocell.Range.InlineShapes(1)
    Set oShape = oInlineShape.ConvertToShape
    oShape.Rotation = 360
    oShape.ConvertToInlineShape
    Set ocell = ActiveDocument.Tables(1).Cell(3, 1)
    Set oInlineShape = ocell.Range.InlineShapes(1)
    Set oShape = oInlineShape.ConvertToShape
    oShape.Rotation = 360
    oShape.ConvertToInlineShape

    Set oInlineShape = Nothing
    Set oShape = Nothing
    Set ocell = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 09-07-2020, 03:25 AM
tyxanu tyxanu is offline VBA to rotate images by selection or another condition? Windows 8 VBA to rotate images by selection or another condition? Office 2013
Novice
VBA to rotate images by selection or another condition?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

This is awesome!

So I am guessing your code targets specific lines(1 and 3)?

But reality is that I always have 50+ lines like those with rotated text and they follow an irregular rule(example: lines 1,2,3,13,15,22,57..etc)

I would have to count all the line numbers and paste them in the code?
Reply With Quote
  #4  
Old 09-07-2020, 04:42 AM
gmayor's Avatar
gmayor gmayor is offline VBA to rotate images by selection or another condition? Windows 10 VBA to rotate images by selection or another condition? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Again based on your example, you could process all the cells in column 1 e.g. as follows (this works with your table without upsetting row 2).



Code:
Sub Macro2()
Dim ocell As Cell
Dim oInlineShape As InlineShape
Dim oShape As Shape
Dim i As Integer
    For i = 1 To ActiveDocument.Tables(1).Rows.Count
        Set ocell = ActiveDocument.Tables(1).Cell(i, 1)
        Set oInlineShape = ocell.Range.InlineShapes(1)
        Set oShape = oInlineShape.ConvertToShape
        oShape.Rotation = 360
        oShape.ConvertToInlineShape
    Next i
    Set oInlineShape = Nothing
    Set oShape = Nothing
    Set ocell = Nothing
End Sub
or if you only want to process some of the rows then


Code:
Sub Macro3()
Dim ocell As Cell
Dim oInlineShape As InlineShape
Dim oShape As Shape
Dim i As Integer
    For i = 1 To ActiveDocument.Tables(1).Rows.Count
        Select Case i
            Case 1, 2, 3, 13, 15, 22, 57
                Set ocell = ActiveDocument.Tables(1).Cell(i, 1)
                Set oInlineShape = ocell.Range.InlineShapes(1)
                Set oShape = oInlineShape.ConvertToShape
                oShape.Rotation = 360
                oShape.ConvertToInlineShape
            Case Else
        End Select
    Next i
    Set oInlineShape = Nothing
    Set oShape = Nothing
    Set ocell = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to rotate images by selection or another condition? Word Art Rotate new_bie Drawing and Graphics 5 01-19-2016 04:11 PM
VBA to rotate images by selection or another condition? Rotate pages Barbee Word 3 01-21-2015 12:03 PM
VBA to rotate images by selection or another condition? How Rotate row of cells 45 degrees? markg2 Excel 2 04-23-2014 05:12 AM
VBA to rotate images by selection or another condition? Rotate text chrislewis Word 3 07-22-2013 08:33 AM
VBA to rotate images by selection or another condition? Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft