Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2017, 08:22 AM
BNystrom BNystrom is offline I need to combine two Word 2010 macros Windows 7 64bit I need to combine two Word 2010 macros Office 2010 64bit
Novice
I need to combine two Word 2010 macros
 
Join Date: Feb 2017
Posts: 2
BNystrom is on a distinguished road
Default I need to combine two Word 2010 macros

I have two macros:
- One that is a simple paste from the clipboard
- The other takes a selected graphic in a document, right aligns it with the column and sets the Text Wrap to "tight".

What I would like is one macro that would paste and align the graphic. Currently, the second macro requires that the item be selected first and I don't know how to do that in VBA. Perhaps there's a simpler way to just apply the attributes I need at the point of pasting the graphic.

Here's what I have currently:

Sub PasteInline()
'
' PasteInline Macro
'
'
Selection.PasteSpecial Placement:=wdInLine
End Sub


Sub RightAlignGraphic()
'
' RightAlignGraphic Macro
'
'

Dim myShape As Shape

If Selection.InlineShapes.Count > 0 Then
Set myShape = Selection.InlineShapes(1).ConvertToShape
ElseIf Selection.ShapeRange.Count > 0 Then
Set myShape = Selection.ShapeRange(1)
Else
MsgBox "Please select a picture first."
Exit Sub
End If

With myShape
.WrapFormat.Type = wdWrapTight
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.Left = wdShapeRight
End With
End Sub


I would greatly appreciate any assistance with combining the functionality of these two macros.



Thanks

Brian
Reply With Quote
  #2  
Old 02-02-2017, 06:14 AM
gmayor's Avatar
gmayor gmayor is offline I need to combine two Word 2010 macros Windows 10 I need to combine two Word 2010 macros Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,143
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 ofgmayor has much to be proud of
Default

Probably somerthing like

Code:
Sub PasteInline()
Dim oRng As Range
Dim oIlShape As InlineShape
Dim oShape As Shape
    Set oRng = Selection.Range
    oRng.Text = ""
    oRng.Paste
    oRng.End = oRng.End + 1
    If oRng.InlineShapes.Count > 0 Then
        Set oIlShape = oRng.InlineShapes(1)
        Set oShape = oIlShape.ConvertToShape
        With oShape
            .WrapFormat.Type = wdWrapTight
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
            .Left = wdShapeRight
        End With
    End If
lbl_Exit:
    Exit Sub
err_Handler:
    Err.Clear
    GoTo lbl_Exit
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 02-02-2017, 06:42 AM
BNystrom BNystrom is offline I need to combine two Word 2010 macros Windows 7 64bit I need to combine two Word 2010 macros Office 2010 64bit
Novice
I need to combine two Word 2010 macros
 
Join Date: Feb 2017
Posts: 2
BNystrom is on a distinguished road
Thumbs up That's perfect!

Many thanks gmayor, that does exactly what I wanted. Hopefully others will find this helpful, too.

EDIT:
After using it for a while, I added the following line under "With Shape" to uncheck the "Move object with text" box under Layout > Position > Options.

.RelativeVerticalPosition = wdRelativeVerticalPositionPage

This allows free movement of the graphic.

Last edited by BNystrom; 02-02-2017 at 08:01 AM. Reason: Added more content
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to combine two Word 2010 macros How to combine several records in a single letter in Word 2010 May Mail Merge 3 03-25-2015 03:36 AM
I need to combine two Word 2010 macros How do I combine two different contentcontrolonexit macros? jamles12 Word VBA 2 11-12-2013 06:51 PM
combine multiple documents word starter 2010 bribelge Word 3 12-19-2012 09:25 AM
I need to combine two Word 2010 macros Macros not working in word 2010 louise_chapman Word VBA 3 10-25-2010 08:34 AM
Macros -Problem Word 2010 Lyn Word VBA 0 08-19-2010 08:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:52 AM.


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