?
Solved

Select .CSV file

Posted on 2011-03-14
4
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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