Excel to Word doc / File Patch -> cell
Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Excel to Word doc / File Patch -> cell
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    New Member
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    49
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Hi Macropod

    Thanks for your support. Should I change something in above code ? I'm asking because it doesn't work

    Regarding saving the outputs to a folder created by VBA, I would also like to create a folder based on text in cell e.g C1 = Reports 22/11/2016. - folder name

    Thanks

    Tomasz

  2. #12
    Retired Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    3,274
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Quote Originally Posted by beczer View Post
    I'm asking because it doesn't work
    If you want help with something, you're going to have to be far more descriotive than that! Precisely what doesn't work? In what way doesn't it work? What error messages, if any, do you get? What data are in cells A1-A3 on the active sheet?

    As for the folder creation, you cannot use anything like 'Reports 22/11/2016' (which you've indicated to be in C1), because a date in that format cannot be used for a folder name.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #13
    New Member
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    49
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Ok, sorry Macropod. You are right.

    Error: compile error: method or data member not found / first line of code - highlighted

    Regarding Folder Creation, that's right. So let's say C1=text, without date.

    Thanks once again!

  4. #14
    Retired Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    3,274
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Quote Originally Posted by beczer View Post
    Error: compile error: method or data member not found / first line of code - highlighted
    The first code line cannot produce that error - not even if you hadn't set a reference to the Word library!
    I did, however, pick up such an error further down. Change:
    StrName = Split(StrName, .docx)(0) & " " & Format(Now, "yyyy-mm-dd hh-mm-ss")
    to:
    StrName = Split(StrName, ".docx")(0) & " " & Format(Now, "yyyy-mm-dd hh-mm-ss")
    Quote Originally Posted by beczer View Post
    Regarding Folder Creation, that's right. So let's say C1=text, without date.
    And where is that folder to be created? Your cell contents don't mention the drive or anything else about the path to that folder. Neither do you mention anything about how or whether that new folder might be used in the code. At a fairly basic level, you could use code like:
    Code:
    On Error Resume Next
    MkDir (StrPth & xlWkSht.Range("C3").Value)
    On Error GoTo 0
    or, with a bit more finesse:
    Code:
    If Dir(StrPth & xlWkSht.Range("C3").Value, vbDirectory) = "" Then MkDir StrPth & xlWkSht.Range("C3").Value
    where StrPth holds the path (including the final "") to wherever the folder name in C3 is to be created.
    Last edited by Macropod; Nov 21st, 2016 at 09:55 PM.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #15
    New Member
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    49
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Macropod THANK YOU !

    It works quite good now. There are just 3 things I would like to change and ask you to help with this:


    1. After creating sucessfully DOC&PDF there is an error -> Run-time error "9" Subscript out of range
    Highlited: StrName = Split(StrName, ".docx")(0) & " " & Format(Now, "yyyy-mm-dd hh-mm-ss")


    2. I can select template path from cell A1-A3 and it works perfect but I would like to change the name of generated files (now it is the same as template name + date). So Is it possible to use template from path in cell A1-A3 and assign new name to DOC&PDF file form different cell e.g B1 ?


    3. The last question. How can I save generated files DOC&PDF directly in generated Folder from cell C3


    Thank you in advance for Your patience and support.

  6. #16
    Retired Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    3,274
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Excel to Word doc / File Patch -> cell

    Quote Originally Posted by beczer View Post
    After creating sucessfully DOC&PDF there is an error -> Run-time error "9" Subscript out of range
    Highlited: StrName = Split(StrName, ".docx")(0) & " " & Format(Now, "yyyy-mm-dd hh-mm-ss")
    That would be because one or more cells in the A1-A3 range is empty. You said all three would have data, so I didn't bother with error-checking code.

    Quote Originally Posted by beczer View Post
    I can select template path from cell A1-A3 and it works perfect but I would like to change the name of generated files (now it is the same as template name + date). So Is it possible to use template from path in cell A1-A3 and assign new name to DOC&PDF file form different cell e.g B1 ?
    Of course you can. The only reason the original name was included was because that's what you specified. BTW, you are not working with templates; you're working with documents. You should learn to name things correctly. Doing otherwise leads to confusion.
    Quote Originally Posted by beczer View Post
    The last question. How can I save generated files DOC&PDF directly in generated Folder from cell C3
    By specifying that as the filepath. You still haven't said what the rest of that path is, though.
    Last edited by Macropod; Nov 24th, 2016 at 09:37 PM. Reason: typo
    Cheers
    Paul Edstein
    [MS MVP - Word]

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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