netrixuser
Board Regular
- Joined
- Jan 21, 2019
- Messages
- 77
- Office Version
- 365
- Platform
- Windows
I hope that made sense !
I have a working script that opens up three Worksheets [report sheets from various applications], renames them, does a bunch formatting and adds a few formulas - all is good except the three files have to be named in a certain way and have to be in the Root directory of the C: drive in order for my script to work.
When the three worksheets are downloaded, the filename contains a date so every month the filenames will be different - hence I ask the users to rename them and place them in the root of C:
I would like the macro to ask where the files are first, so the filenames and location is irrelevant as the user can browse to the files - and upon Googling I found this code, wich is a good start but I need to tweak it slightly. The code appears to open up the last folder that the user opened up, so I would like to force it to look in the Downloads folder (which is the default for the Worksheets to be downloaded to) The issue I have is that the path to the Download folder contains the Users Windows Name.
This is the code I found:
I have tried the ChDir command but cannot figure out how to add a variable to the ChDir statement so it would read something like:
I have managed to get the Windows User Name into a cell in the Spreadsheet that runs the script (ie opens the three reports up etc) using:
This puts my Windows Name in cell A1, changes the font colour to white etc but I still am unable to get the Windows Name into the path statement so that the Application.GetOpenFileName always looks in the correct directory !
HELLPP !!
Thanks for any advice
NetrixUser
I have a working script that opens up three Worksheets [report sheets from various applications], renames them, does a bunch formatting and adds a few formulas - all is good except the three files have to be named in a certain way and have to be in the Root directory of the C: drive in order for my script to work.
When the three worksheets are downloaded, the filename contains a date so every month the filenames will be different - hence I ask the users to rename them and place them in the root of C:
I would like the macro to ask where the files are first, so the filenames and location is irrelevant as the user can browse to the files - and upon Googling I found this code, wich is a good start but I need to tweak it slightly. The code appears to open up the last folder that the user opened up, so I would like to force it to look in the Downloads folder (which is the default for the Worksheets to be downloaded to) The issue I have is that the path to the Download folder contains the Users Windows Name.
This is the code I found:
Code:
[COLOR=#333333]Sub OpenFileDialog()[/COLOR]' Defines variables
Dim TargetFile As Variant
' Open dialogue box to browse for file
TargetFile = Application.GetOpenFilename _
(Title:="Please choose a file to open", _
FileFilter:="Excel Files *.xls* (*.xls*),")
' If no file is selected then...
If TargetFile = False Then
' Display message box with an error
MsgBox "No file selected.", vbExclamation, "Sorry!"
' Exit the macro
Exit Sub
' Else if a valid file is selected then...
Else
' Open the selected workbook
Workbooks.Open FileName:=TargetFile
End If
[COLOR=#333333]End Sub[/COLOR]
I have tried the ChDir command but cannot figure out how to add a variable to the ChDir statement so it would read something like:
Code:
ChDir "C:\Users\USER'S WINDOWS NAME HERE\Downloads"
I have managed to get the Windows User Name into a cell in the Spreadsheet that runs the script (ie opens the three reports up etc) using:
Code:
UserName = Environ$("UserName")
Range("A1:A1").Select
With Selection
.Font.Color = vbWhite
ActiveCell = UserName
End With
Range("A2:A2").Select
HELLPP !!
Thanks for any advice
NetrixUser