Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Copy Selection to a Batch File

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy Selection to a Batch File

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

"DaveM" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy Selection to a Batch File

DaveM,

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

Mike

"DaveM" wrote:

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Copy Selection to a Batch File

Works a Treat

Thanks Mike

All the best

Dave



"Mike H" wrote in message
...
DaveM,

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

Mike

"DaveM" wrote:

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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy Selection to a Batch File

Your welcome and thanks for the feedback


"DaveM" wrote:

Works a Treat

Thanks Mike

All the best

Dave



"Mike H" wrote in message
...
DaveM,

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

Mike

"DaveM" wrote:

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






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
batch process to covert file to excel file [email protected] Excel Programming 4 February 22nd 08 10:09 PM
Copy Selection - Paste Selection - Delete Selection Uninvisible Excel Programming 2 October 25th 07 01:31 PM
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM
How to Copy a project plan to Excel through macro or batch file? Project to Excel Excel Programming 0 January 4th 06 05:19 AM
Create a batch file from a number of Excel File Vinay[_2_] Excel Programming 0 September 8th 04 01:11 AM


All times are GMT +1. The time now is 07:24 AM.

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"