• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Select .CSV file

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
Seamus2626
Asked:
Seamus2626
  • 2
  • 2
1 Solution
 
nutschCommented:
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
 
Seamus2626Author Commented:
Thanks Thomas!
0
 
nutschCommented:
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
 
Seamus2626Author Commented:
Thats fine, will only ever have one.

Cheers,
Seamus
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now