Copy Selection to a Batch File

D

DaveM

Hi

How would I extent this code to save the cells selected to save it to a
batch file c:\Comment2.Bat

Sub CopyNextCOMMENTSBATCHFILE()

Dim ws As Worksheet, ws2 As Worksheet
Dim rngfound As Range
Dim rng As Range
Dim toFind As String
Set ws = Worksheets("COMMENTS1")
Set ws2 = Worksheets("COMMENTS2")
Set rng = ws2.Columns("A:A")
toFind = ws.Range("F8").Value
With rng
Set rngfound = .Find(toFind, lookat:=xlWhole, LookIn:=xlValues)
End With
If Not rngfound Is Nothing Then
Application.Goto ws2.Range("A" & rngfound.Row), Scroll:=True
End If
ActiveCell.Offset(0, 1).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
End Sub

Thanks in advance

Dave
 
M

Mike H

Dave

add this to the end of your code

Selection.Copy 'don't bother copying
Open ("c:\comments.bat") For Append As 1
For Each c In Selection
Write #1, (c.Text)
Next
Close #1

mike
 
M

Mike H

DaveM,

On reflection use this line
Print #1, (c.Text)
instead of
Write #1, (c.Text)

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top