Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA code to Paste into a specific text file
I have a macro that i run. The last part is to copy the data.
I then click over to an open text document and paste where the curser is, which is at the bottom of the most recient data pasted. Is there a way to have excel automatically, paste/export/whatever into a specific text doc saved on my HD. I have to do this hundreds of times to compile and any step i can automate is helpful. Thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA code to Paste into a specific text file
Something like this should do what you want:
Sub SaveToTextAppend(strFullPath As String, strText As String) Dim hFile As Long hFile = FreeFile Open strFullPath For Append As hFile Print #hFile, strText Close #hFile End Sub Sub test() SaveToTextAppend "C:\testfile.txt", "just testing appending some text" End Sub Keep in mind that if the file doesn't exist it will be made, so if you don't want that you will have to test for the presence of the file first. RBS "dcozzi" wrote in message ... I have a macro that i run. The last part is to copy the data. I then click over to an open text document and paste where the curser is, which is at the bottom of the most recient data pasted. Is there a way to have excel automatically, paste/export/whatever into a specific text doc saved on my HD. I have to do this hundreds of times to compile and any step i can automate is helpful. Thanks. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA code to Paste into a specific text file
RB,
Thanks for getting back to me. I am a real newbie when it comes to VBA. Below is the code from the macro I am using to manipulate the data and them paste it into a text file called "EXPORT" which is saved on my desktop. To use this macro, I copy the data I am going to use from another source. Then I run this macro. If possible, can you past the code you provided below into my code. I keep getting errors. The file I need to output to is located at this directory C:\Documents and Settings\DCozzi\Desktop\Export The current macro code is as follows. Thanks for your help. Sub PROCESS() ' ' Macro4 Macro ' Macro recorded 3/8/2006 by Daniel Cozzi ' ' Sheets("IMPORT").Select Selection.AutoFilter Cells.Select Selection.ClearContents Sheets("OUTPUT").Select Range("E1").Select ActiveSheet.Paste Selection.Replace What:="]", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Columns("F:F").Select Selection.Replace What:=".", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Range("A2:D2").Select Selection.AutoFill Destination:=Range("A2:D30000"), Type:=xlFillDefault Range("A3:D30000").Select Columns("A:BU").Select Selection.Copy Sheets("IMPORT").Select Columns("A:A").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Cells.Select Selection.ColumnWidth = 20 Range("A1").Select Sheets("OUTPUT").Select Columns("E:E").Select Range(Selection, Selection.End(xlToRight)).Select Selection.ClearContents Rows("3:3").Select Range(Selection, Selection.End(xlDown)).Select Selection.ClearContents Sheets("IMPORT").Select Cells.Select Application.CutCopyMode = False Selection.AutoFilter Selection.AutoFilter Field:=5, Criteria1:="<" Columns("A:AF").Select Selection.Copy Sheets("CONTROL").Select End Sub "RB Smissaert" wrote: Something like this should do what you want: Sub SaveToTextAppend(strFullPath As String, strText As String) Dim hFile As Long hFile = FreeFile Open strFullPath For Append As hFile Print #hFile, strText Close #hFile End Sub Sub test() SaveToTextAppend "C:\testfile.txt", "just testing appending some text" End Sub Keep in mind that if the file doesn't exist it will be made, so if you don't want that you will have to test for the presence of the file first. RBS "dcozzi" wrote in message ... I have a macro that i run. The last part is to copy the data. I then click over to an open text document and paste where the curser is, which is at the bottom of the most recient data pasted. Is there a way to have excel automatically, paste/export/whatever into a specific text doc saved on my HD. I have to do this hundreds of times to compile and any step i can automate is helpful. Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy/Paste Rows that Contain Specific Text | Excel Worksheet Functions | |||
Text File Encode to UTF-8_Unicode specific | Excel Programming | |||
Cut - Paste in xls file (c++ code) | Excel Programming | |||
Code-Copy & Paste in Text Boxes | Excel Programming | |||
VBA Code- Copy and paste into a generic text box | Excel Programming |