Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

VBA code to Paste into a specific text file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dcozzi - 17 Mar 2006 22:25 GMT
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.
RB Smissaert - 18 Mar 2006 10:40 GMT
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

>I have a macro that i run. The last part is to copy the data.
>
[quoted text clipped - 6 lines]
>
> Thanks.
dcozzi - 21 Mar 2006 21:01 GMT
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

> Something like this should do what you want:
>
[quoted text clipped - 32 lines]
> >
> > Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.