+ Reply to Thread
Results 1 to 12 of 12

Excel to Word- paragraph and page setup

  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    Kentucky
    MS-Off Ver
    Excel 2010
    Posts
    9

    Excel to Word- paragraph and page setup

    Greetings!

    How to I use VBA in excel 2010 to create a new document in MS Word 2010 which has 0.5 inch margins (right, left, top and bottom), is portrait orientation, uses Verdana 12 point font, has single line spacing, and does not have points before nor after the paragraph?

    The Word document opens using this code:
    Please Login or Register  to view this content.
    Thanks!
    Last edited by MWXA; 09-08-2011 at 11:12 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Excel to Word- paragraph and page setup

    Record you macro in MSWord and use that in your Excel macro. These links should help as well.
    'TypeText method
    ' http://www.excelforum.com/excel-prog...ml#post1946784
    ' http://www.excelforum.com/showthread.php?p=1946784
    ' http://vbaexpress.com/forum/showthread.php?p=169877
    ' http://vbaexpress.com/forum/showthread.php?t=24693

  3. #3
    Registered User
    Join Date
    07-21-2011
    Location
    Kentucky
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Excel to Word- paragraph and page setup

    When I create a macro in Word, I get this code:
    Please Login or Register  to view this content.
    When I insert this into the previous code after wdApp.Visible = True and try to run the macro, I get an error message: "Sub or Function not defined" and the debugger highlights "InchesToPoints".

    Thanks!

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel to Word- paragraph and page setup

    Be smart, create a new word document with all the properties you need.
    Save this Wordfile as "E:\example.doc"

    Open it in Excel using:

    Please Login or Register  to view this content.



  5. #5
    Registered User
    Join Date
    07-21-2011
    Location
    Kentucky
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Excel to Word- paragraph and page setup

    I do have a word document setup and bookmarked to add the values to the document that I use. However, there are 6 other users of the workbook and I would like to generate a word document for them on their machines. When a macro is run to generate a word document, the default margins and paragraph for their normal template is used and there is variation in this "normal" template from user to user. Thus, I want to create the Word document and define the page setup and paragraph setup instead of using the normal templates.

    With the above code generating an error message, it seems that I need to define or reference the document somehow.

    Thanks,

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel to Word- paragraph and page setup

    Why not sending those users a copy of the correctly formatted document ?

  7. #7
    Registered User
    Join Date
    07-21-2011
    Location
    Kentucky
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Excel to Word- paragraph and page setup

    Quote Originally Posted by snb View Post
    Why not sending those users a copy of the correctly formatted document ?
    That is not an option that I want to pursue at this time. I want to use VBA to create the word document and also define the page setup and paragraph setup.

    Thanks

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Excel to Word- paragraph and page setup

    Your code is for Word's VBA using it's defaults. You are doing it in Excel's VBA which uses it's defaults. So, after you make the Word Application object reference called say "wa" as shown in my first example link, do wa.Selection. Selection by itself assumes the Selection is for the Excel application.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel to Word- paragraph and page setup

    Hello MWXA,

    Welcome to the Forum!

    Perhaps this version of the macro is what you after...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  10. #10
    Registered User
    Join Date
    07-21-2011
    Location
    Kentucky
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Excel to Word- paragraph and page setup

    Thanks to the good folks above, here is the code that worked:
    Please Login or Register  to view this content.

  11. #11
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Excel to Word- paragraph and page setup

    I would recommend that you add the Word constants since you are using late binding. You probably have the Word object referenced which is why that code worked.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel to Word- paragraph and page setup

    or

    Please Login or Register  to view this content.

+ 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