Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy/Paste Rows that Contain Specific Text Mike Woodard Excel Worksheet Functions 1 March 8th 06 07:35 PM
Text File Encode to UTF-8_Unicode specific [email protected] Excel Programming 1 December 16th 05 09:59 AM
Cut - Paste in xls file (c++ code) allen Excel Programming 0 June 23rd 05 09:50 AM
Code-Copy & Paste in Text Boxes Bourbon[_27_] Excel Programming 1 January 28th 04 12:53 AM
VBA Code- Copy and paste into a generic text box Bourbon[_18_] Excel Programming 0 January 23rd 04 02:42 PM


All times are GMT +1. The time now is 09:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"