+ Reply to Thread
Results 1 to 9 of 9

Copy Contents of a text file and paste it in command prompt

Hybrid View

szpt9m Copy Contents of a text file... 01-09-2014, 04:42 AM
ragulduy Re: Copy Contents of a text... 01-09-2014, 05:45 AM
szpt9m Re: Copy Contents of a text... 01-09-2014, 06:12 AM
szpt9m Re: Copy Contents of a text... 01-09-2014, 06:28 AM
Marc L Re: Copy Contents of a text... 01-09-2014, 06:28 AM
ragulduy Re: Copy Contents of a text... 01-09-2014, 06:37 AM
szpt9m Re: Copy Contents of a text... 01-09-2014, 10:27 PM
Marc L Re: Copy Contents of a text... 01-10-2014, 05:45 AM
szpt9m Re: Copy Contents of a text... 01-10-2014, 05:56 AM
  1. #1
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Copy Contents of a text file and paste it in command prompt

    Hi All,

    I need a vba code to copy all contents of a input text file and paste it in a command shell.. Please help me..

    Thank you.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copy Contents of a text file and paste it in command prompt

    Maybe something like:
    Sub macro_1()
    Shell "Cmd.exe /S /K " & createobject("Scripting.filesystemobject").opentextfile("E:\temp.txt").read
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Copy Contents of a text file and paste it in command prompt

    Quote Originally Posted by yudlugar View Post
    Maybe something like:
    Sub macro_1()
    Shell "Cmd.exe /S /K " & createobject("Scripting.filesystemobject").opentextfile("E:\temp.txt").read
    End Sub
    Hi Thanks for replying..

    I used the code but getting wrong number of arguments or invalid property assignment error.. Pls help..

    i am using below code
    Shell "Cmd.exe /S /K " & CreateObject("Scripting.filesystemobject").OpenTextFile(renameFilePath).Read
    where rename file path is the file path from textbox.

    Thanks

  4. #4
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Copy Contents of a text file and paste it in command prompt

    Shell "Cmd.exe /S /K " & CreateObject("Scripting.filesystemobject").OpenTextFile(renameFilePath).ReadAll
    Read all method is working only for one line.. but i want it to process all lines

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Copy Contents of a text file and paste it in command prompt


    Hi,

    no needs a command shell, just read the VBA help of Name statement !

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copy Contents of a text file and paste it in command prompt

    Maybe try:
    Sub macro_1()
    Shell "Cmd.exe /S /K " & Replace(CreateObject("Scripting.filesystemobject").opentextfile("E:\test.txt").readall, vbNewLine, "")
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Copy Contents of a text file and paste it in command prompt

    Quote Originally Posted by yudlugar View Post
    Maybe try:
    Sub macro_1()
    Shell "Cmd.exe /S /K " & Replace(CreateObject("Scripting.filesystemobject").opentextfile("E:\test.txt").readall, vbNewLine, "")
    End Sub
    Hi,

    This is also processing only one line...

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Copy Contents of a text file and paste it in command prompt


    With the txt file attached …

  9. #9
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Copy Contents of a text file and paste it in command prompt

    solved by changing the naming of the file from .txt to .bat and running it using Shell command.. Thanks all.

+ 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. Replies: 1
    Last Post: 10-01-2012, 11:11 PM
  2. Macro to copy & paste the contents of a docx file into xls?
    By Cheshire in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2010, 02:48 PM
  3. Copy contents of cell and paste in text box
    By Ricardo9211 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2009, 01:02 AM
  4. Macro to copy column contents into a text file
    By vinaynagasani in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2009, 03:25 AM
  5. Replies: 7
    Last Post: 07-04-2006, 03:20 AM

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