creating automated macro autopop

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Creating an automated macro that autopopulates a worksheet from

Creating an automated macro that autopopulates a worksheet from

resolvedResolved · High Priority · Version 2007

Astley has attended:
Access Advanced course

Creating an automated macro that autopopulates a worksheet from

I'm trying to creating a command macro coded button on a spreadsheet (excel 2007) that retrieves and auto- populates a worksheet of data stored in a csv file format located on a F:Drive on a directory. Is this possible to do? If so, do you have any ideas how this can be done?
Ultimately the user will just click on the command button to display the data rather than go through various steps to the directory in order to retrieve the data.


Thanks for your contribution

RE: Creating an automated macro that autopopulates a worksheet f

Hi Astley,

Thank you for your question.

Please find the VBA code below:
------------------------------------------------------------------------
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\Simon\Desktop\Carhires.csv", Destination:=Range("a1"))
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
---------------------------------------------------------------------------

This code might not be the most effective and possibly not the quickest way of doing it but it has worked for a friend in the past. This will connect to a CSV file and dump the data into cell A1 of the active sheet.

1. Go to the worksheet and select the Developer Tab.
2. If the Developer tab is not present then go to Office button and click the developer checkbox on the popular options.
3. Click the Insert button on the Controls group.
4. Select the Active X Command Button and draw a button out on the sheet.
5. Right click over the button and choose View Code.
6. Within the Sub and End Sub copy the code above and adjust it with the relevant path.
7. Then switch off Design Mode and test the button.

I hope this answers your question.

Regards

Simon

RE: Creating an automated macro that autopopulates a worksheet f

Thanks!

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Adding up time greater than 24 hours

When you add up time if it exceeds 24 hours i.e 27 hours appears as 03:00. Go to Format / Cells / Number / Custom. The format is hh:mm but if change it to [hh]:mm it will add up to the correct amount of hours.

View all Excel hints and tips


Server loaded in 0.09 secs.