+ Reply to Thread
Results 1 to 12 of 12

Header when creating report from Excel to Word

  1. #1
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Header when creating report from Excel to Word

    Hi I Have this code which creates a header in Word from Excel.

    it looks like this:

    Please Login or Register  to view this content.
    But an error occurs on the last row Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify

    What I want to create with that row is that I want the header to be nice centerd.

    Here are the screen shots demonstrating the issue.

    This is how it is using the code. ( not what I want )

    Picture 1.jpg


    and this is how I want it to look

    Picture 2.png



    I would appreciate the help!
    Last edited by RinorM; 05-30-2014 at 07:37 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    You have to add the wdApp else Excel thinks you're refering to Excel Selection.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Header when creating report from Excel to Word

    Hi! It helped what you suggested, I didn't get an error anymore. Thank you. But thing is I didn't get the header to become like picture 2 above. Any ideas on why not?

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    I think you need a right alignment, not a Justify.

  5. #5
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Header when creating report from Excel to Word

    Hi I tried using wdApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphRightAlignment

    But it didn't work.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    Go to the Word program, load the document, then turn on Show All Formatting Marks and see if there are any tabs embedded in the correct version.

    File-> Options>Display>Show All Formatting Marks

    If this doesn't work, I'll need a sample Excel/Word documents.

  7. #7
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Header when creating report from Excel to Word

    Hi I did try it but there was not any tab there. I have posted the worksheet of the Excel document that creates this word document if you can take a look. The macro that runs it is called "CreateRapport".



    Excelforum help.xlsm

    I am very thankful for you taking the time to help me.

  8. #8
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    I think I've got it.

    You'll never get the format correct by building strings of characters in Excel and pasting them to Word. RESISTANCE IS FUTILE!

    So, I've added a table in the header so that normal paragraph formatting can be added.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Header when creating report from Excel to Word

    Hey Tinbendr! The code worked very well, thank you very much! I have one more question The picture below happens when i modify the code a bit:

    Excelforum.jpg

    How can I make it so that the tables come within the margins in the word document ?


    The code I added is


    Please Login or Register  to view this content.


    What the code does is that it makes it possible to run the macro without having the sheet "rapport" open.

    Thank you for the help mister.

  10. #10
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    Since we're not using Selection, you can even comment this out.
    Please Login or Register  to view this content.
    I actually forgot to remove it earlier.

    No need to make sheet visible, so...
    Please Login or Register  to view this content.
    As far as the table width is concerned, if it continues to be a problem, you'll have to set columns widths in the table. Which might prove a challenge since you're copy & pasting the range from Excel to Word.

    It doesn't exceed the width on my machine.

  11. #11
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Header when creating report from Excel to Word

    Try changing this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-28-2014
    Location
    Sverige
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: Header when creating report from Excel to Word

    Hi David. The code that did the thing was this one:

    Please Login or Register  to view this content.
    I tried changing
    Please Login or Register  to view this content.
    but it didn't help about the problem with the table widths. If you got any other sudgestions about changing it you could always send me a message about it ! Anyway I am very thankful for your help since you sorted out many problems out for me. THANK YOU!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Creating report in word with VBA
    By RinorM in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2014, 10:57 AM
  2. Creating a Word Report from Excel Data
    By donnarenia in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-12-2013, 02:09 AM
  3. Using EXCEL VBA to create word ,insert header in word, add textbox in header and fill pic
    By xiaorenwuhyl in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2013, 05:32 AM
  4. [SOLVED] Add Header/Footer to excel report from ASP..
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-01-2006, 10:10 PM
  5. [SOLVED] Add Header/Footer to excel report from ASP..
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2006, 07:40 PM

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