paste data other csv
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Paste in data from other from csv file

Paste in data from other from csv file

resolvedResolved · Low Priority · Version 2007

replyReply Thu 19 May 2011, 14:48Delegate Tom said...

Tom has attended:
Excel VBA Intro Intermediate course

Paste in data from other from csv file

Hi,

I am currently trying to obtain the code in order for me to open a csv file. copy the data in it and paste it into a sheet in my current workbook. then also close the csv file i had opened.

The code i have at the moment is as follows:-

ilName = Application.GetOpenFilename(FileFilter:="csv files,*.csv", Title:="Select Settlement File", _
MultiSelect:=False)

Workbooks.Open filName

If Err.Number = "1004" Then
MsgBox ("Please Choose Settlement File")
End If

Range("A1").CurrentRegion.Copy
ActiveWindow.Close
Sheets("Settlements").Range("A1").Paste
Range("A31").Select


All seems to work ohk expect i get a pop up when closing the csv file which i do not want and a was wondering is there any other better/quiker ways to do this?

Many thanks for your help

For upcoming training course dates see: Pricing & availability

replyReply Tue 24 May 2011, 12:46Trainer Anthony said...

RE: Paste in data from other from csv file

Hi Tom, thanks for your query. You could just import the csv data onto a new worksheet and copy it from there. Here's a tidied up subroutine generated from the macro recording of a CSV import (via From Text on the data tab).

Sub import_CSV()

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\Anthony\Documents\My Dropbox\Application Support\Anthony Desktop\Book1.csv" _
, Destination:=Range("$A$1"))
.Name = "Book1"
.FieldNames = True
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With
End Sub


Hope this helps,

Anthony

Tue 31 May 2011: Automatically marked as resolved.

 

Please browse our web site to find out more about
access+training+courses and other Microsoft training courses.

Access tip:

Relationship maps

It is important to create proper relationships between tables. You can use Access to help check your designs and evaluate them by printing them in graphical format to help with design purposes


Click on the Tools menu, click Relationships.
On the File menu, click Print Relationships. View or print as required

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard