User Prompted Macro?

evmike123

New Member
Joined
Jun 13, 2019
Messages
1
Hello I am new to excel and VBA coding and have not been able to figure out how to complete what I would like to do. I have been able to make simple macros but this is more in depth I believe. The goal: Create a macro that when the excel file is opened the user will be brought to a specific file that Csv. files will be saved with data. The user will then choose the desired file that will be imported into the excel file that they opened in order continue with the information. I appreciate your time and any info you can provide for me! Thank you
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,
This is a quick solution that I have cobbled together, when the document is opened it will open the location of your choice and only show CSV fie formats.
if the person cancels the file choosing it will not care and just sit as a blank XLSM file.

You may want to also do something about when the user saves as I am guess you will not want this XLSM format....but that's something else to think about in the future :)


Code:
Private Sub Workbook_Open()
On Error Resume Next
Dim ws As Worksheet, strFile As String
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "C:\" 'set you default file location here
Set ws = ActiveWorkbook.Sheets("Sheet1") 'set to current worksheet name if required
strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")
End With
With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
     .TextFileParseType = xlDelimited
     .TextFileCommaDelimiter = True
     .Refresh
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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