Solved

Can I link (connect) a table to a dynamic CSV file based on cell values for folder and filename using VBA?

Posted on 2016-09-15
2
28 Views
Last Modified: 2016-10-20
Every month I send a CSV file to different users, that they should analyse in Excel.

I have attached a spreadsheet that has the VBA, that I have been using to import into Excel for them, and this is followed by a pivottable that gives the users the possibility to analyse data.

Unfortunately this does not import data to an Excel Table, which will give me a more flexible way of expanding/change the size of my dataset.

I have created the import and analysis using PowerQuery and it Works great. Unfortunately does many of my users not have access to PowerQuery, and I need to do the same in Basic Excel and use some VBA to do the same trick.

The procedure is called OpenCsv and it imports the data to the the sheet "Vederlagsspecifikation" based on the two inputs of folder and filename in the sheet "Vejledning"

If you have any questions or need to me to clarify my problem, please just ask.

best regards

Jørgen
100575-VL000274.csv
Test-af-import-af-csv-fil.xlsb
0
Comment
Question by:Jorgen
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41799546
Hi,

pls try

Sub Change_DataSource()

 
strNewURL = Sheets("Vejledning").Range("A2") & Sheets("Vejledning").Range("A1")
Set tbl = Sheets("Vederlagsspecifikation").QueryTables(1)
 
With tbl
    If .Connection <> "TEXT;" & strNewURL Then
        .Connection = "TEXT;" & strNewURL
        .Refresh
    End If
End With

End Sub

Open in new window

Regards
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41851697
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Rgonzo1971 (https:#a41799546)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

863 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

23 Experts available now in Live!

Get 1:1 Help Now