-
Notifications
You must be signed in to change notification settings - Fork 11
/
Excel Access VBA - Files.vb
50 lines (39 loc) · 1.27 KB
/
Excel Access VBA - Files.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Sub opening_Uploading_File()
'
' This asks the user to upload a specific file
'
Dim user_Selected_File As Variant
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All Excel Files", "*.xlsx"
.Show
'Gets the path of the file / Dir() gets the name in the path
user_Selected_File = Dir(.SelectedItems(1), vbNormal)
End With
msgbox user_Selected_File
'Dim k(0) As Variant
'k(0) = Split(user_Selected_File, ".")
'user_Selected_File = k(0)(0)
End Sub
Public Sub renaming_File(ByVal file_Name As String)
'
' This gives a file a new name
'
Dim fso As FileSystemObject
Dim fso_Folder As Folder
Dim fso_File As file
Dim new_File_Name As String
Set fso = New FileSystemObject
Set fso_Folder = fso.GetFolder("C:\Users\Zadig\Documents\Access Databases\")
Set fso_File = fso_Folder.Files("Import.xlsx")
'Set new file name
new_File_Name = "Imports_" & Year(Date) & ".xlsx"
'When not "imports", change name
If file_Name <> "Imports" Then
fso_File.Name = new_File_Name
End If
Set fso = Nothing
Set fso_File = Nothing
Set fso_Folder = Nothing
End Sub