+ Reply to Thread
Results 1 to 4 of 4

Opening Notepad a saved notepad file and copying the data on it

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Opening Notepad a saved notepad file and copying the data on it

    Hi,

    I'm trying to merge edit 2 types of codes...

    1. That Opens a notepad file
    2. Copies the Data and automatically closes out notepad

    Part 2 works if your sending data from an excel sheet to the notepad but I need it to work from oepning a notepadfile directly.

    For some reason,

    The File will open with no issue but the data on the notepad won't copy.
    (I want it to copy (Highlight) blue so after the notepad automatically closes, I can just paste the data to it's destination.


    here is the code...


    Dim Shex As Object
    Set Shex = CreateObject("Shell.Application")
    tgtfile = "C:\Folder Location Goes Here"
    Shex.Open (tgtfile)
    
    
    ''Start Notepad And let it recieve focus
    '    Shell "notepad.exe", vbNormalFocus
    
    'Send the keys CTRL+V To Notepad (i.e the window that has focus)
    '    SendKeys "^V"
    '
    'Copy whats on the Clipboard
    SendKeys "^a"
    SendKeys "^c"
    
        
    waitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 10)
    Application.Wait waitTime
        
    Application.SendKeys "%{F4}", True
    Application.SendKeys "{TAB}", True
    Application.SendKeys "{ENTER}", True
    
    
    'End Sub
            
    End Sub

    Please Help

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Opening Notepad a saved notepad file and copying the data on it

    How about instead

    Sub Main()
      Dim sText         As String
    
      sText = File2Str("C:\somePath\someFile.txt")
    End Sub
    
    Function File2Str(sFile As String) As String
      ' Adapted from Andy Pope
      ' Returns a text file as a string
      Dim iFile         As Integer
    
      If Len(Dir(sFile)) Then
        iFile = FreeFile
        Open sFile For Binary Access Read As #iFile
        File2Str = Input(LOF(iFile), iFile)
        Close iFile
      End If
    End Function
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Opening Notepad a saved notepad file and copying the data on it

    Quote Originally Posted by shg View Post
    How about instead

    Sub Main()
      Dim sText         As String
    
      sText = File2Str("C:\somePath\someFile.txt")
    End Sub
    
    Function File2Str(sFile As String) As String
      ' Adapted from Andy Pope
      ' Returns a text file as a string
      Dim iFile         As Integer
    
      If Len(Dir(sFile)) Then
        iFile = FreeFile
        Open sFile For Binary Access Read As #iFile
        File2Str = Input(LOF(iFile), iFile)
        Close iFile
      End If
    End Function

    Absolutely Nothing Happens when I run that Code

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Opening Notepad a saved notepad file and copying the data on it

    Did you change the literal string to point to a file that actually exists?

    Did you step through Main and look at the contents of the variable sText?

+ 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: 3
    Last Post: 10-16-2014, 01:30 PM
  2. Remove marching ants after notepad macro opens notepad
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-07-2014, 09:47 PM
  3. how to copy selected notepad text and paste it in other notepad with macro
    By Guru232 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 04-24-2013, 04:43 AM
  4. Copying more than one range of data from excel into more than one notepad file
    By brianQ in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 01:25 PM
  5. copying data from excel into notepad
    By walid66 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-19-2007, 03:58 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