Windows Vista Forums

how to paste a text file to word with vba

  1. #1


    ts Guest

    how to paste a text file to word with vba

    how to paste with vba or vbscript a text file ( which is actually a director
    listing: dir a-dir/b) into the new line after the cursor is sitting?
    or is it possible to use vbscript to add to end of a closed word document
    the content of a test file?
    I have the vbscript for creating the desired directory listing in a
    temporary text file.

    however I have not figure how to get the context of the into the word
    document nor clipboard

    tried IE


    Dim objIE
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate(sLstCurrentFn) ' ("about:blank")
    objIE.document.select()
    document.parentwindow.copy() ' error below

    ---------------------------
    Windows Script Host
    ---------------------------
    Script: C:\DOCUME~1\lgary\LOCALS~1\Temp\z.vbs
    Line: 35
    Char: 1
    Error: Object doesn't support this property or method: 'document.select'
    Code: 800A01B6
    Source: Microsoft VBScript runtime error

    ---------------------------
    OK
    ---------------------------





      My System SpecsSystem Spec

  2. #2


    mr_unreliable Guest

    Re: how to paste a text file to word with vba



    ts wrote:

    > how to paste with vba or vbscript a text file ( which is actually a director
    > listing: dir a-dir/b) into the new line after the cursor is sitting?
    > or is it possible to use vbscript to add to end of a closed word document
    > the content of a test file?
    > I have the vbscript for creating the desired directory listing in a
    > temporary text file.
    >
    > however I have not figure how to get the context of the into the word
    > document nor clipboard
    >
    > tried IE
    >
    >
    > Dim objIE
    > Set objIE = CreateObject("InternetExplorer.Application")
    > objIE.Navigate(sLstCurrentFn) ' ("about:blank")
    > objIE.document.select()
    > document.parentwindow.copy() ' error below
    >
    > ---------------------------
    > Windows Script Host
    > ---------------------------
    > Script: C:\DOCUME~1\lgary\LOCALS~1\Temp\z.vbs
    > Line: 35
    > Char: 1
    > Error: Object doesn't support this property or method: 'document.select'
    > Code: 800A01B6
    > Source: Microsoft VBScript runtime error
    >
    > ---------------------------
    > OK
    > ---------------------------
    >
    >

      My System SpecsSystem Spec

  3. #3


    mr_unreliable Guest

    Re: how to paste a text file to word with vba

    ts wrote:

    > how to paste with vba or vbscript a text file ( which is actually a director
    > listing: dir a-dir/b) into the new line after the cursor is sitting?
    hi ts,

    What you are looking for is "insert => file" (look for the
    "insert" menu item, and the "file... " submenu item.

    I'm not going to suggest any code, but you can do that for
    yourself using the "macro recorder". Bring up your document,
    then turn on the macro recorder. Go through the operations
    you want to record, such as inserting your text file into
    your document, then turn off the recorder.

    What you get is a "macro" recorded in the vba language.
    You can use it in msWord as is, _or_ you can do the entire
    thing via script. You instantiate msWord ("Word.Application"),
    open your file, and then "convert your vba macro to script", to
    get your text file inserted into the word document. (note:
    converting the macro is pretty easy, with only a couple of
    "gotchas" -- which can ge easily found by (adv) googling
    this ng).

    cheers, jw
    ____________________________________________________________

    You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
    the answers will be applicable to the questions)


    --- <boilerplate: using macro recorder to script msWD/XL> ---
    I don't have any scripts handy, but my standard advice for
    a situation like this is to turn on your excel macro recorder,
    go through the operation you want to do "manually" (say, for
    the first two worksheets), then turn off the macro recorder.

    Go to the editor for macros, and pick out the vba macro code.
    You then convert the vba to vbs -- not too hard to do -- but
    there are a couple of things to watch out for. The most
    common "thing to watch out for" is named arguments to functions
    or subs. You are going to have to enter the argument values
    (without the names) in their proper order.

    A more definitive statement of "things to watch out for"
    (when converting vba to vbs) may be found in the ng archives.
    Go to: http://groups.google.com/advanced_group_search

    Also, there are many postings about using excel's automation
    interface, and converting vba to vbs in this very newsgroup,
    which can also be located using google's group search.
    --- <end of macro recorder boilerplate> ---



      My System SpecsSystem Spec

  4. #4


    mr_unreliable Guest

    sorry about that...

    mr_unreliable wrote:

    >
    >
    ???
    mr_unreliable clicked the wrong button, sorry.

      My System SpecsSystem Spec

  5. #5



    Newbie
    Join Date : Mar 2009
    Posts : 1
    64
    Local Time: 04:58 PM


     

    Re: how to paste a text file to word with vba

    Dear Sir,

    I have the same problem as you in my profession I use text files and the data and writes to word inserting text and images. Below you will find 2 links to my badly styled home page that I have for fun. There are two macro codes one for extracting data from one text file and one program that lists all files in a directory combined you can extract data from muliple text files. Code for writing to word I have not added yet but will do so within a few hours hopefully!!! Enjoy

    http://vbaexcel.eu/vba-macro-code/list-files-in-directory

    Read Text File Fetch Data

    vba-macro-code

    Quote Originally Posted by ts View Post
    how to paste with vba or vbscript a text file ( which is actually a director
    listing: dir a-dir/b) into the new line after the cursor is sitting?
    or is it possible to use vbscript to add to end of a closed word document
    the content of a test file?
    I have the vbscript for creating the desired directory listing in a
    temporary text file.

    however I have not figure how to get the context of the into the word
    document nor clipboard

    tried IE


    Dim objIE
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate(sLstCurrentFn) ' ("about:blank")
    objIE.document.select()
    document.parentwindow.copy() ' error below

    ---------------------------
    Windows Script Host
    ---------------------------
    Script: C:\DOCUME~1\lgary\LOCALS~1\Temp\z.vbs
    Line: 35
    Char: 1
    Error: Object doesn't support this property or method: 'document.select'
    Code: 800A01B6
    Source: Microsoft VBScript runtime error

    ---------------------------
    OK
    ---------------------------

      My System SpecsSystem Spec

how to paste a text file to word with vba

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Stored Copy/Paste Text??? nigel4sher General Discussion 1 01 Jan 2010
Unable to paste from web to word KathyB Microsoft Office 6 13 Jun 2009
HELP! Can't paste links or text from internet wapwap Browsers & Mail 1 17 Nov 2008
Copy / Paste from Word Bicky Vista General 3 17 Feb 2008
How do you copy and paste text in Vista?? Nicole Vista General 4 13 Jan 2008