+ Reply to Thread
Results 1 to 8 of 8

Textbox to notepad

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2012
    Location
    Watford, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Textbox to notepad

    Hi

    Ive been using this code to copy 30 textboxes into a word document. How can i change it to do the same in noetpad?


    Sub CreateNewNightReport()
    Dim sTmpString As String
         'Opens new word document - GM
         Dim objWord As Object
    
    Set objWord = CreateObject("Word.Application")
    
        Dim i As Integer
        Set wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = True
        Set wrdDoc = wrdApp.Documents.Add
    
       'Copies TextBox1 into word document - GM
        
        sTmpString = ActiveSheet.TextBox1.Value
    
        With wrdApp
            .Selection.TypeText Text:=sTmpString
            .Selection.TypeParagraph
        End With
    
    
        'Copies TextBox2 into word document - GM
        
        sTmpString = ActiveSheet.TextBox2.Value
        
        
        With wrdApp
            .Selection.TypeText Text:=sTmpString
            .Selection.TypeParagraph
        End With    
    
     Set wrdDoc = Nothing
     Set wrdApp = Nothing
    
    End Sub
    thanks inadvance
    Last edited by mr_mead; 07-22-2013 at 07:11 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Textbox to notepad

    please add code tags to your post

    are you trying to append the data to an existing text file or create a new one?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    12-13-2012
    Location
    Watford, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Textbox to notepad

    Create a new .txt file everytime

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Textbox to notepad

    please add code tags to your post ;-)

    where are these textboxes? in a Word document? (this is not the Word forum)

  5. #5
    Registered User
    Join Date
    12-13-2012
    Location
    Watford, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Textbox to notepad

    How do i add codes tags? I thought i had.

    I have 2 reports which both download to word. I originally put it together with google within excel and have since moved it to a different report within word. I've edited the text to show the excel version.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Textbox to notepad

    ok-how do you want the data added to the text file-separate line per textbox or all on one line with a delimiter?

  7. #7
    Registered User
    Join Date
    12-13-2012
    Location
    Watford, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Textbox to notepad

    Seperate line per text box would be great.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Textbox to notepad

    Sub writeToFile()
       Dim n As Long
       Dim lFile As Long
       Dim sPath As String
       
       ' change path
       sPath = "C:\some file.txt"
       
       lFile = FreeFile
       
       Open sPath For Output As lFile
       
       For n = 1 To 30
          Print #lFile, ActiveSheet.OLEObjects("Textbox" & n).Object.Text
       Next n
       
       Close lFile
       
    End Sub
    for instance

+ 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. 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
  2. VBA - Macro Code to copy textbox text to another worksheet textbox
    By nitram lowm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2013, 08:39 AM
  3. Macro to copy textbox data to a duplicate textbox in another worksheet
    By nitram lowm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2013, 06:10 AM
  4. Replies: 3
    Last Post: 05-07-2012, 09:46 PM
  5. Userform: Pass textbox values to another textbox on button press
    By adjustermn in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2010, 11:19 PM

Tags for this Thread

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