Solved

Select .CSV file

Posted on 2011-03-14
4
236 Views
Last Modified: 2012-05-11
Hi,

Im looking to copy over some data from one file to another, i cant use workbook.activate("XYZ.xls") because the file name changes each day, i donr want to use activate next workbook as the user may have multiple workbooks open.

Can i select the workbook to paste into based the on the fact it finishes .CSV as opposed to .xls

So something like

select.'code'
Copy entire workbook
Select "xyz.xls"
Paste into sheet "abc"

Select CSV file
Close
Dont save changes

Thanks!
Seamus
0
Comment
Question by:Seamus2626
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 35130048
Hi Seamus, you can use code like this to get your csv workbook

Dim wbk As Workbook, wbkCSV As Workbook

For Each wbk In Application.Workbooks
    If UCase(Right(wbk.Name, 4)) = ".CSV" Then
        Set wbkCSV = wbk
        GoTo foundCSV
    End If
Next

MsgBox "CSV not found"
Exit Sub
foundCSV:

'continue your paste and close

Open in new window


Thomas
0
 

Author Closing Comment

by:Seamus2626
ID: 35130392
Thanks Thomas!
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35130494
Glad to help. One warning: this will take the first csv workbook found, which could be an issue if you have more than one open.

T
0
 

Author Comment

by:Seamus2626
ID: 35130604
Thats fine, will only ever have one.

Cheers,
Seamus
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now