+ Reply to Thread
Results 1 to 7 of 7

Problem with styles in automation of Word creation

  1. #1
    Registered User
    Join Date
    11-28-2011
    Location
    Barcelona
    MS-Off Ver
    Excel 2007
    Posts
    74

    Problem with styles in automation of Word creation

    Hello,

    I have created a code that automates the creation of a Word Document when I send to it two arrays with data.

    The code is the following:

    Please Login or Register  to view this content.
    Everything works OK except for the part where this code is executed:

    Please Login or Register  to view this content.
    If I write it for instance, beneath the part:

    Please Login or Register  to view this content.
    The Header 1 Style appears correctly.

    "str" is always a string.

    I have tried including:

    Please Login or Register  to view this content.
    and it doesn't solve the problem either.

    Apart from that, every second time I execute the code from excel, I have a server errors, as if the object was still existing, but actually, I close it in the end with this code, so I don't guess where the problem is:

    Please Login or Register  to view this content.
    I would much appreciate your assistance.

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

    Re: Problem with styles in automation of Word creation

    Do not use VBA to format a Word document.
    Make a Word template of the report, including all the formatting.
    Use Docvariables to transfer data from Excel to the Worddocument.



  3. #3
    Registered User
    Join Date
    11-28-2011
    Location
    Barcelona
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Problem with styles in automation of Word creation

    Do you mean to use bookmarks?

    Can you address me to any url where I could learn about working this way?

    I have searched for Doc variables, VBA, Excel, Word and I don't obtain clear references.

    Thanks for your help.

  4. #4
    Registered User
    Join Date
    11-28-2011
    Location
    Barcelona
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Problem with styles in automation of Word creation

    I found this:

    http://books.google.co.uk/books?id=V...page&q&f=false

    Is it the solution you are suggesting?

  5. #5
    Registered User
    Join Date
    11-28-2011
    Location
    Barcelona
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Problem with styles in automation of Word creation

    I have searched through teh forum and found:

    http://www.excelforum.com/excel-prog...in-fields.html
    http://www.excelforum.com/word-forma...ith-excel.html

    But it seems as this method is very rigid: 1 docvariable -> 1 value

    It means that the number of elements has to be always the same.

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

    Re: Problem with styles in automation of Word creation

    Save both files in the same directory.
    Open the Excel file.
    Use the macro in the Excel file.

  7. #7
    Registered User
    Join Date
    11-28-2011
    Location
    Barcelona
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Problem with styles in automation of Word creation

    Hello snb,

    First of all, thank you for your code and for your help. I had done a code of my own based on the threads I linked (some of them you had answered yourself).

    I have downloaded your code and tried to test it, but it drawed an error (it didn't find the file/class name). I used a replace function to change "\\" into "\" and with both files open (with the word file closed it didn't work) it worked.

    What I wonder is that if I need the following structure:

    Please Login or Register  to view this content.
    in which I can have an indeterminate quantity of Budgets, labs and persons, is it possible to work with DOCVARIABLES? As far as I can see, I must create one DOCVARIABLE for each of these indeterminate elements...

    Thanks in advance for your assistance.

+ 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