copy a file

Joe C

Well-known Member
Joined
Oct 17, 2002
Messages
841
I have a routine that imports a bunch of data into access, to find all the relevant materials.
It then saves atxt file of those materials. I want to copy that txt file to the clipboard so user can save a copy of it where they like as oppsed to the area where my access routine saves it. How would I copy a file to clip (as a file) so when macro ends I will instruct user to paste in the location he chooses.

Many thanks for any help.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
One way:
Code:
Sub FileToClipboard()
    ' requires a reference to Microsoft Forms Object Library
    Const sFile As String = "C:\myFile.txt"
 
    With New DataObject
        .SetText File2Str(sFile)
        .PutInClipboard
    End With
End Sub
 
Function File2Str(sFile As String) As String
    ' Adapted from Andy Pope
    ' Returns a text file as a string
    Dim iFF       As Integer
 
    If Len(Dir(sFile)) Then
        iFF = FreeFile
        Open sFile For Binary Access Read As #iFF
        File2Str = Input(LOF(iFF), iFF)
        Close iFF
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top