Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2015, 02:05 AM
NobodysPerfect NobodysPerfect is offline Significant performance problem when duplicating or pasting shape Windows 8 Significant performance problem when duplicating or pasting shape Office 2010 32bit
Competent Performer
Significant performance problem when duplicating or pasting shape
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default Significant performance problem when duplicating or pasting shape

Hi to all,



I’d be glad if anyone could help me with some very slow cold.

Given: Shape (in front of text) in the first cell of a table. Shape properties:
Code:
With Shp
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .Height = CentimetersToPoints(2.63)
    .Top = CentimetersToPoints(1.66)
    .Left = CentimetersToPoints(2.57)
    .Name = “ShapeToInsert”
End With
Wanted: Copy/Paste or Duplicate/Move Shape into all cells of the table.

Problem: Whatever way I try as soon as the shape is pasted / duplicated, the properties .Left and .Top get lost. Which means, I need a second loop to adjust .Top and .Left again. Unfortunately the formatting takes about one second per shape.

Do you have any idea how to improve the code or do you even see another approach than mine?

Any help appreciated – as always
NP
Reply With Quote
  #2  
Old 03-30-2015, 02:59 AM
gmayor's Avatar
gmayor gmayor is offline Significant performance problem when duplicating or pasting shape Windows 7 64bit Significant performance problem when duplicating or pasting shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

Assuming there is only one table in the document, you could use mail merge processes to speed things up.

With the image already placed in the first cell add the following to duplicate it to the rest of the table. Even with a large table it is pretty well instantaneous.
Code:
Dim oDoc As Document
Dim oFld As field
    Set oDoc = ActiveDocument
    With oDoc.MailMerge
        .MainDocumentType = wdMailingLabels
        WordBasic.MailMergePropagateLabel
        .MainDocumentType = wdNotAMergeDocument
    End With
    For Each oFld In ActiveDocument.Tables(1).Range.Fields
        If oFld.Type = wdFieldNext Then oFld.Delete
    Next oFld
__________________
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 03-30-2015, 03:37 AM
NobodysPerfect NobodysPerfect is offline Significant performance problem when duplicating or pasting shape Windows 8 Significant performance problem when duplicating or pasting shape Office 2010 32bit
Competent Performer
Significant performance problem when duplicating or pasting shape
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default

Hi,

great idea - but ... I did not mention this in my OP because I didn't have a mail merge solution in my mind.

There is aleady one InlineShape in each table cell. The inserted Shape should be on top of the InlineShape. As I'm not a mail merge expert, I really don't know if, and if yes, how to realize that challange.

Sorry for not mentioning this earlier.

NP
Reply With Quote
  #4  
Old 03-30-2015, 05:15 AM
gmayor's Avatar
gmayor gmayor is offline Significant performance problem when duplicating or pasting shape Windows 7 64bit Significant performance problem when duplicating or pasting shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

If it is the same inline shape in each cell of the table, the macro will duplicate everything in the first cell of the table to all the other cells. You don't have to know anything about mail merge, you just have to put the required images in the first cell.

The macro simply uses a function of mail merge to duplicate the cells.

If they are different images in each cell, then the approach will not work.
__________________
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
  #5  
Old 03-30-2015, 12:00 PM
NobodysPerfect NobodysPerfect is offline Significant performance problem when duplicating or pasting shape Windows 8 Significant performance problem when duplicating or pasting shape Office 2010 32bit
Competent Performer
Significant performance problem when duplicating or pasting shape
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default

Quote:
You don't have to know anything about mail merge, you just have to put the required images in the first cell.


It is the same inline shape in each cell of the table, so your code it works fine and fast.

Thanks
NP
Reply With Quote
  #6  
Old 04-02-2015, 03:24 AM
NobodysPerfect NobodysPerfect is offline Significant performance problem when duplicating or pasting shape Windows 8 Significant performance problem when duplicating or pasting shape Office 2010 32bit
Competent Performer
Significant performance problem when duplicating or pasting shape
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default

Quote:
If they are different images in each cell, then the approach will not work.
A fast solution for different images in cells:
Save formatted shape as autotext in normal.dot(m), insert autotext in each cell, delete autotext entry in normal.dot(m).

Cheers
NP
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Significant performance problem when duplicating or pasting shape Performance problem ActiveX radio buttons NobodysPerfect Word VBA 8 05-31-2014 03:51 AM
Word 2000--Problem with format retention when pasting JerryL Word 2 01-05-2014 07:20 PM
Copy and pasting problem Word 2010 Sarah262 Word 3 08-16-2012 03:46 PM
Significant performance problem when duplicating or pasting shape Office '03 + '07-->Performance? markg2 Office 1 08-04-2011 06:09 AM
Pasting problem Alec Word 1 11-09-2009 12:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:56 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