+ Reply to Thread
Results 1 to 8 of 8

Center All

  1. #1
    Forum Contributor
    Join Date
    06-12-2007
    Posts
    144

    Center All

    I am using Excel to create a document in Word.
    I can get it to paste 2 images into the document, and set the page widths etc.

    But I cannot get it to center both images.

    I am not even entirely sure if the fist one is a "picture" as it wont let me resize it the way it lets me resize the second one!
    When I use the macro recorder in Word it wont even let me select the first picture.
    And I dont know how to reference it cos I dont know its name...

    I have tried to use .Selection.WholeStory and shapes.selectall but to no avail.
    but maybe i just didnt do it right

    Can anybody help me?!


    I have attached the output Word document, and my Excel Code is:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Try:

    Please Login or Register  to view this content.
    BTW, you have a duplicate line that needs to be deleted:

    Please Login or Register  to view this content.
    HTH

    Jason
    Last edited by jasoncw; 01-14-2009 at 10:45 AM.

  3. #3
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    On your attached Word document, if I select all (CTRL + a), then click the paragraph align center button, it centers both images.

  4. #4
    Forum Contributor
    Join Date
    06-12-2007
    Posts
    144
    Unfortunately that didnt work :-(
    It didnt center either of them.


    I know the CTRL+A then center works when you are in Word, but I cant seem to replicate that in code.

    Can I "sendkeys" to do that perhaps?

  5. #5
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    The code I posted above should replicate it. I used it on the Word document you posted above, and it worked for me. Try this:

    Open the Word document you need to center the images.
    Type ALT + F11 to get into VBE.
    Type CTRL + g to go to the immediate window.
    Copy the below code in the immedate window, and hit Enter.

    Please Login or Register  to view this content.
    Does it center the images?

    Jason

  6. #6
    Forum Contributor
    Join Date
    06-12-2007
    Posts
    144
    Yes that did work in Word.

    However the exact same line doesnt work from my excel code:

    Please Login or Register  to view this content.
    Could it be because its really saying:

    Please Login or Register  to view this content.
    ?

    I have done a work-around, so its not urgent. But it is still interesting, and it would be an improvement.

    I just made both images the same size, and set the page margins so that the images are in the middle by default.

  7. #7
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    I set up a dummy file, and it worked just fine for me. Here is something else to try.

    When you are in the Excel file, go into the VBE. Select Tools > References, then make sure "Microsoft Word xx.x Object Library" is checked.

  8. #8
    Forum Contributor
    Join Date
    06-12-2007
    Posts
    144

    Smile

    Aha! Yes that is the problem.

    Unfortunately I need it to work on other peoples computers without them having to change anything.
    I know there are ways to set it via code, but I think I'll just leave it.
    It works ok as it is now.

    Thanks very much for your help, its nice to get to the bottom of it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1