Hello,
New member here, so i feel a small introduction is in order:
I am an engineer residing in Kentucky, born and raised in Chicago, IL.
Right now the current purposes of my excel tasks are for work, in where I am developing a number of applications to assist my company in simplifying various routine data analysis tasks.
I am relatively new to VBA code in general, and the extent of my knowledge is entirely self-taught using resources such as this forum.
My question:
I am working on writing a string of code to allow a user to select a file (.CSV) to be used in further parts of the sub.
Right now I have been able to use .GetOpenFilename to select a file, and import the selected .csv file into a fixed sheet.
However, the only issue i have with this method is that i really do not need the file selected to open, as i just need the path for further processes.
So, is there a way i can modify my code to prevent the selected file from opening all together while still using .GetOpenFilename or is there some other method that will accomplish what i need?
I have searched through the various posts regarding .GetOpenFilename with no luck, so i figure that i am probably just using .GetOpenFilename when i should be using something else.
Like i said, everything works without issue, but i just want to prevent the file selected from actually opening.
(However I still have yet to add some code to exit sub when user cancels the file selection window)
Thank you
New member here, so i feel a small introduction is in order:
I am an engineer residing in Kentucky, born and raised in Chicago, IL.
Right now the current purposes of my excel tasks are for work, in where I am developing a number of applications to assist my company in simplifying various routine data analysis tasks.
I am relatively new to VBA code in general, and the extent of my knowledge is entirely self-taught using resources such as this forum.
My question:
I am working on writing a string of code to allow a user to select a file (.CSV) to be used in further parts of the sub.
Right now I have been able to use .GetOpenFilename to select a file, and import the selected .csv file into a fixed sheet.
However, the only issue i have with this method is that i really do not need the file selected to open, as i just need the path for further processes.
So, is there a way i can modify my code to prevent the selected file from opening all together while still using .GetOpenFilename or is there some other method that will accomplish what i need?
I have searched through the various posts regarding .GetOpenFilename with no luck, so i figure that i am probably just using .GetOpenFilename when i should be using something else.
Code:
Dim Filename
'Browse for .CSV file to analyze
Filename = Application.GetOpenFilename( _
"Comma Separated Values (*.csv),*.csv", _
Title:="Select CSV File")
If Filename <> "False" Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Workbooks.Open Filename, Format:=2
End If
' Further on, i use "Filename" in the string to import the CSV as such.
' "Dump" is us the sheet it sends to, i have omitted some code
'import data from CSV file selected
With Dump.QueryTables.Add(Connection:= _
"TEXT;" & Filename, Destination:=Dump.Range("$A$1"))
.Name = "test"
.FieldNames = True
' middle code omitted
.Refresh BackgroundQuery:=False
End With
Like i said, everything works without issue, but i just want to prevent the file selected from actually opening.
(However I still have yet to add some code to exit sub when user cancels the file selection window)
Thank you