[FONT="]0
Low Priority ?
0 Views
Last Modified: 2018-06-29
Edit Question
[/FONT]
[FONT="]I have used this Excel 2016 macro - that was written for me - but I have been told on another site that some parts of it are unsafe.
I am not familiar with VBA so I would like to make it safe to use.
"You shouldn't use dir() function to list files in a folder as it is an unsafe function.
It is better to use the FSO library.
The global ActiveSheet object, Sheets and Worksheets collections for the very same reason"
Sub InsertImages()
Dim WS As Worksheet
Dim StrFile As String
Dim strFolder As String
Dim strFilter As String
strFolder = ""
strFilter = "*.*"
With Application.FileDialog(mso<wbr style="font-size: 16px; font-family: inherit;">FileDialog<wbr style="font-size: 16px; font-family: inherit;">FolderPick<wbr style="font-size: 16px; font-family: inherit;">er)
.Title = "Choose folder"
.InitialFileName = "d:"
If .Show = -1 Then strFolder = .SelectedItems(1)
End With
StrFile = Dir(strFolder & "" & strFilter)
Do While Len(StrFile) > 0
Set WS = Sheets.Add(After:=Sheets(W<wbr style="font-size: 16px; font-family: inherit;">orksheets.<wbr style="font-size: 16px; font-family: inherit;">Count))
WS.Activate
ActiveSheet.Pictures.Inser<wbr style="font-size: 16px; font-family: inherit;">t(strFolde<wbr style="font-size: 16px; font-family: inherit;">r & "" & StrFile).Select
StrFile = Dir
Loop
End Sub[/FONT]
[FONT="]
[/FONT]
Low Priority ?
0 Views
Last Modified: 2018-06-29
Edit Question
[/FONT]
[FONT="]I have used this Excel 2016 macro - that was written for me - but I have been told on another site that some parts of it are unsafe.
I am not familiar with VBA so I would like to make it safe to use.
"You shouldn't use dir() function to list files in a folder as it is an unsafe function.
It is better to use the FSO library.
The global ActiveSheet object, Sheets and Worksheets collections for the very same reason"
Sub InsertImages()
Dim WS As Worksheet
Dim StrFile As String
Dim strFolder As String
Dim strFilter As String
strFolder = ""
strFilter = "*.*"
With Application.FileDialog(mso<wbr style="font-size: 16px; font-family: inherit;">FileDialog<wbr style="font-size: 16px; font-family: inherit;">FolderPick<wbr style="font-size: 16px; font-family: inherit;">er)
.Title = "Choose folder"
.InitialFileName = "d:"
If .Show = -1 Then strFolder = .SelectedItems(1)
End With
StrFile = Dir(strFolder & "" & strFilter)
Do While Len(StrFile) > 0
Set WS = Sheets.Add(After:=Sheets(W<wbr style="font-size: 16px; font-family: inherit;">orksheets.<wbr style="font-size: 16px; font-family: inherit;">Count))
WS.Activate
ActiveSheet.Pictures.Inser<wbr style="font-size: 16px; font-family: inherit;">t(strFolde<wbr style="font-size: 16px; font-family: inherit;">r & "" & StrFile).Select
StrFile = Dir
Loop
End Sub[/FONT]
[FONT="]
[/FONT]