+ Reply to Thread
Results 1 to 21 of 21

Help needed converting part of a spreadsheet into a Word document table please

  1. #1
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Help needed converting part of a spreadsheet into a Word document table please

    Hi All,

    My Excel price list contains many rows of items and when I want to produce a quote for a customer I end up having to manually fill in a table in my quote Word document which is very time consuming as you can imagine. I am a relative newbie when it comes to Excel and I was wondering whether some kind soul could provide some help please?

    I've attached both a snapshot Excel and Word document. What I would like to happen, is for me to enter the Qty and Area details into the spreadsheet and select 'y' or 'n' to include this information into the Word document table. I only would want the Make, Description, Total Cost included in the Word table and a single instance of the Area as per the Word document attached.

    Could anyone lend me a hand please and advise whether what I'm trying to achieve is possible?

    Many thanks
    Daz
    Attached Files Attached Files

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    One way. See attached.
    Attached Files Attached Files
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Hi Paul,

    Thank you ever so much for the reply. That certainly helps a lot. Is there a way to a) only have one instance of the area name and each area being in its own row as in my original Word document example? Lastly, I noticed in your Word file Expr1003. I'm not sure what that is but can it be changed to read Cost or Price?

    Best wishes
    Daz

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    If you use the document with the workbook I returned, you shouldn't be getting the Expr1003.

    As for having only one instance of the area name and each area being in its own row, AFAIK that's not possible with a DATABASE field (which is what the document uses). Of course, you could use a macro to unlink the DATABASE field after updating (or not), then do whatever further formatting you require. If you don't unlink the DATABASE field after updating, any reformatting you do is liable to be lost when next the field updates (e.g. at print time).

  5. #5
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Hi Paul,

    Most of what you just replied with has gone right over my head I'm afraid and I was fearing this may happen!

    Is there another way of producing this?

    Many thanks
    Daz

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    OK, to see how the document gets its data, open it and press Alt-F9. There you'll see a field code:
    Please Login or Register  to view this content.
    To update the data and the formatting, add the following macro to the document:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    That's absolutely incredible Paul. Thanks very much!

    One thing I noticed though is that if I have two Area names, which are the same by the way, but in different rows on the spreadsheet, the Word table doesn't group the items under one Area name. I assume this is because the commands and macro are working on a row by row basis. Is that correct and can anything be done? For example, the rows pasted from the spreadsheet below...

    ANTH GALLO M1Y SINGLE M1Y NUCLEUS MICRO(1) HAG8 £200.00 1 £200.00 Master Bedroom y

    ANTH GALLO ADIVABHG ADIVA L/S SINGLE BK HAGE £250.00 2 £500.00 Main Equipment y

    ANTH GALLO ADIVAWHT ADIVA L/S SINGLE WH HAGG £250.00 5 £1,250.00 Master Bedroom y

    ...Look like this in the Word table:-

    Master Bedroom ANTH GALLO - M1Y NUCLEUS MICRO(1) 1 £200.00
    Main Equipment ANTH GALLO - ADIVA L/S SINGLE BK 2 £500.00
    Master Bedroom ANTH GALLO - ADIVA L/S SINGLE WH 5 £1,250.00

    Rather than just the one Area called Master Bedroom containing two rows of data.

    Best wishes
    Daz

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Try the following version of the macro:
    Please Login or Register  to view this content.
    It might be a good idea to edit the field code, too by inserting AS `Total Cost` before FROM, viz:
    Please Login or Register  to view this content.
    Last edited by macropod; 04-27-2021 at 09:25 AM.

  9. #9
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Hi Paul,

    I've uploaded the spreadsheet and word document again as it contains (hopefully!), the macro. You can see what I'm getting rather than me pasting the results here. Certainly a lot better but still not grouping the products together.

    I guess, I could always sort the Area column A to Z but that puts some rows of data in part for the Word table that I wouldn't want them (such as cables, Installation, etc.)

    Best wishes
    Daz
    Attached Files Attached Files

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Word docx files cannot contain macros...

    I see you've changed the workbook name but the DATABASE field is still pointing to the original workbook. You've also omitted the workbook tags for the 'Cables required for the project' and 'Installation & setup' lines, which throws the macro out.
    Last edited by macropod; 04-27-2021 at 09:42 AM.

  11. #11
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    I reverted back to the original workbook name and put the 'Cables required for the project' and 'Installation & setup' lines back in and re-run the macro. Looks great apart from one very odd thing. If you look at the v2 sheet I sent you you should see two rows with Bathroom in the Area column. For some reason, in the Word table it lists them like this:-

    Bathroom ANTH GALLO - MICRO SINGLE SPK 1 £150.00
    Bathroom ANTH GALLO - ADIVA L/S SINGLE SS 1 £275.00

    (I padded the second line item with extra spaces as the first row cost and qty format appears to be left justified for some strange reason)

    Cheers
    Daz

  12. #12
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Try the following version of the macro:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    That looks wonderful!

    I guess it's important for me to understand how the field codes thing you've done for the Word document works (teach a man to fish yada yada). Are you able or even willing to walk me through it so that I can learn and alter it should I need to?

  14. #14
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Also, and I'm a little afraid to ask more of your time but when a quote is prepared I generally don't list the cost of each item, I simply provide a total cost per Area and then a Total project cost at the end of the document. Is it somehow possible to hide / omit the Total Cost column in the Word document and have a total per Area? I've attached an example.

    Many thanks
    Daz
    Attached Files Attached Files

  15. #15
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Quote Originally Posted by dazzys View Post
    I guess it's important for me to understand how the field codes thing you've done for the Word document works (teach a man to fish yada yada). Are you able or even willing to walk me through it so that I can learn and alter it should I need to?
    As previously discussed, the document employs a DATABASE field, for which the code is represented in post #8.

    Most of the work is done by an SQL query in the field code (everything from "SELECT to 'Y'"). You'd really need to learn some SQL to fully understand that part, though I'm sure you can get a sense of what it's doing.

    The '\d' '\s', and ' \l "1" \b "1663" \h' strings are a series of what Word calls switches to delineate what different parts of the field are doing and to control the table's appearance. Those are documented at https://support.microsoft.com/en-us/...9-558a87badcbc. Unfortunately, there's no documentation I can refer you to for the \l and \b switches that say exactly how they're affecting the table formatting - you'd need to create the DATABASE field via Insert|Quick Parts and experiment with the different table formats there to see what you get, then look at the resulting field code.

    The "{FILENAME \p}/../GHPRICE SNAPSHOT.xlsx" string, as you can see, tells the DATABASE field where the source file is. The '{FILENAME \p}/../' part is something I've employed to tell the field to look in the same folder as the document itself. This isn't standard field coding, but I've documented its use at: https://www.msofficeforums.com/word/...nal-files.html

  16. #16
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Quote Originally Posted by dazzys View Post
    I generally don't list the cost of each item, I simply provide a total cost per Area and then a Total project cost at the end of the document. Is it somehow possible to hide / omit the Total Cost column in the Word document and have a total per Area?
    Try:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Simply wonderful! Tiny snag...for some reason it's not including a cost figure for the Cables required for the project. I'm sure that's a simple fix?

  18. #18
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Change:
    SngVal = CSng(StrTmp): .Cell(r, 4).Range.Text = vbNullString
    to:
    SngVal = CSng(StrTmp): If r < .Rows.Count - 2 Then .Cell(r, 4).Range.Text = vbNullString

  19. #19
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    That's brilliant!

    Going forward are the names of both the excel and word files important and if so, how would I go about editing the field code and macro to ensure it works?

    Many thanks
    Dazz

  20. #20
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Help needed converting part of a spreadsheet into a Word document table please

    The Word document's name is unimportant.

    Provided you keep the Word document and the Excel workbook in the one folder, it doesn't matter which folder that might be on your system.

    If you change the Excel workbook's name, or want to use a different workbook, you would need to change 'GHPRICE SNAPSHOT' in the DATABASE field to match. Likewise, if you change the Excel worksheet name, you would need to change 'GHPRICE' in the DATABASE field to match.

  21. #21
    Registered User
    Join Date
    08-10-2018
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Help needed converting part of a spreadsheet into a Word document table please

    Hi. Just returning to this after a few months as I unfortunately suffered a heart attack and my thoughts were elsewhere for obvious reasons. I seem to be getting myself muddled up with all the above changes to the database and macros. Would there be any chance you could put just one file together for me to try again with please?

+ 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. [SOLVED] How to Generate a Word document, using VBA, and using part of the data on excel?
    By sylvainsyl20 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-12-2016, 09:58 AM
  2. [SOLVED] Help: converting new sheets to word document
    By Vaughan.jamie in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-17-2015, 08:19 AM
  3. converting a MS word document to Excel
    By jon@karhu in forum Excel General
    Replies: 6
    Last Post: 02-10-2009, 02:55 PM
  4. Hyperlink to a specific part of a Word document
    By anar_baku in forum Excel General
    Replies: 3
    Last Post: 01-15-2009, 06:10 AM
  5. Replies: 1
    Last Post: 06-01-2006, 09:55 AM
  6. Converting a Word Document to excel
    By KelB in forum Excel General
    Replies: 2
    Last Post: 03-13-2006, 05:10 AM
  7. Converting a Word document into an Excel one
    By Rageaholic in forum Excel General
    Replies: 2
    Last Post: 06-20-2005, 05:21 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