macro button to read csv file

excel01noob

Board Regular
Joined
Aug 5, 2019
Messages
93
Office Version
  1. 365
  2. 2016
I want to share a Microsoft Excel Macro-Enabled Worksheet (.xlsm) with a button which any user could click and run macro code.

It would tell user if the csv file is opened or not.
If open, then the code would run, and any data change is to be performed in that .csv file.


how do I put this in practice?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
If you had a CSV file located on the Desktop ... and the active workbook you were using with the command button ... the following would open
that CSV file :

VBA Code:
Workbooks.Open ActiveWorkbook.Path & "\Temp.csv", Local:=True

Download example files : CSV.zip
 
Upvote 0
I receive the CSV file via email which I usually open first.

The Microsoft Excel Macro-Enabled Worksheet (.xlsm) is not on my desktop but on a personal directory C:\My docs\Macro

Can I run the macro without the need to save the CSV file (prior to the changes needed after the run of the macro code)?
 
Upvote 0
If you can determine the directory path to the CSV file, then change the path in the code provided.
 
Upvote 0
I was not able to find the directory path, how do I do it? (I am assuming that the CSV file is not saved, just opened).

Can I setup a Sub on the Macro enabled file to check if there is a file named "report.csv" (the report received monthly has always this name) opened and then to use that csv file as being the Active workbook so to run the rest of the code?
 
Upvote 0
Can I setup a Sub on the Macro enabled file to check if there is a file named "report.csv" (the report received monthly has always this name) opened and then to use that csv file as being the Active workbook so to run the rest of the code?

I believe you can.
 
Upvote 0
I managed to do this sub which work for what I want.

But I am hard-coding the file name Raw_data_Report.csv in my code and would prefer to have it on a cell visible to any user (and updated in that cell if the filename changes)

Anyone knows how to replace that by cell N12 from the Template workbook?


Sub CHECK_OPEN_FILE()

Application.ScreenUpdating = False
'+++++++++++++++++++++++++++++++
'Twb is the template workbook
'Dwb is destination workbook

Dim Twb As Workbook
Dim Dwb As Workbook

Set Twb = ActiveWorkbook

Set Dwb = Nothing
On Error Resume Next
Set Dwb = Workbooks("Raw_data_Report.csv")

On Error GoTo 0

If Dwb Is Nothing Then
MsgBox "Raw_data_Report is not open!"
Else

'change to destination workbook

Dwb.Activate

End If

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top