+ Reply to Thread
Results 1 to 1 of 1

export data from excel 2003 into NOTEPAD

Hybrid View

  1. #1
    Registered User
    Join Date
    04-01-2009
    Location
    racine, wi
    MS-Off Ver
    Excel 2003
    Posts
    1

    export data from excel 2003 into NOTEPAD

    I need to copy a range of cells A1:A20 from worksheet: Assy_txt_export
    and paste it into NOTEPAD.

    Also is there a way to name the textfile using the data from cell A24
    from worksheet: Assy_txt_export.

    Andrew P was nice enough to make this version for me, but I need to replace the Sub(test)) portion with a notepad command "Shown Below". (I'm having issues with Quotes in the text file) and Notepad seems to take care of this issue.

    From AndY P
    ---------------------------------------------
    Declare Function SHGetSpecialFolderLocation Lib "Shell32.dll" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
    Declare Function SHGetPathFromIDList Lib "Shell32.dll" Alias "SHGetPathFromIDListA" _
    (ByVal pidl As Long, ByVal pszPath As String) As Long
    Public Type SHITEMID
        cb As Long
        abID As Byte
    End Type
    Public Type ITEMIDLIST
        mkid As SHITEMID
    End Type
    Public Const MAX_PATH As Integer = 260
    Public Const CSIDL_DESKTOP = &H0 '// The Desktop - virtual folder
    Public Function fGetSpecialFolder(CSIDL As Long) As String
        Dim sPath As String
        Dim IDL As ITEMIDLIST
        fGetSpecialFolder = ""
        If SHGetSpecialFolderLocation(0, CSIDL, IDL) = 0 Then
            sPath = Space$(MAX_PATH)
            If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
                fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & ""
            End If
        End If
    End Function
    Sub Test()
        Dim ShNew As Worksheet
        Dim FName As String
        Dim Folder As String
        Set ShNew = Worksheets.Add
        With ThisWorkbook.Worksheets("Assy_txt_export")
            .Range("A1:A20").Copy ShNew.Range("A1")
            FName = .Range("A24").Value
        End With
        Folder = fGetSpecialFolder(CSIDL_DESKTOP)
        FName = Folder & Application.PathSeparator & FName
        With ShNew
            .SaveAs Filename:=FName, FileFormat:=xlTextWindows
            Application.DisplayAlerts = False
            .Delete
            Application.DisplayAlerts = True
        End With
    End Sub
    -----------------------------------------------

    I found this part on a forum, but I don't know anything about VB.
    Can someone tweek it so it shows it is copying the info from worksheet: Assy_txt_export
    And have it name the text file using the data from cell A24 from the same worksheet?

    **************************************
    Sub notepad()
        Range("A1:A20").Copy
        '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"
    
    '
    End Sub
    ****************************************

    Feel free to contact me @: [email protected]
    This way I can send a powerpoint slide showing what I'm trying to do.

    Thank you for your support
    Rob
    Last edited by Leith Ross; 04-02-2009 at 12:51 PM. Reason: Corrected Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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