VB Excel Dir function on folder with security
up vote
0
down vote
favorite
I've got some VB code which loops files in folders and prints their name and size into an excel sheet.
The code picks up the folder name from the top row.
If I click on the link to the folder from Excel, I can see the items in the folder. If I point to a different folder, it works fine, however when set to a specific folder "\serverd$folder1folder2folder3", it returns nothing.
In the folder specified above, I have read only access. Is this why I can't see the results?
Does anyone know how to amend the VB to show the files?
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, file As Variant, n As Long
Dim i As Long, a As Long, filesiz As Long
Range(Cells(2, 1), Cells(100000, 10)).Delete
i = 1
While (i <= 10)
directory = Cells(1, i).Value
If directory = "" Then
Exit Sub
End If
file = Dir(directory, vbNormal)
n = 2
While (file <> "")
If InStr(file, ".sub") = 0 And InStr(file, ".blb") = 0 Then
Add = 0
If i > 1 Then
While (InStr(Cells(n + Add, 1), file)) = 0 And Cells(n + Add, 1).Value <> ""
Add = Add + 1
Wend
End If
While (Cells(n + Add, i).Value <> "")
Add = Add + 1
Wend
filesiz = FileLen(directory & file)
Cells(n + Add, i).Value = file & " " & filesiz '& " " & FileDateTime(directory & file)
n = n + 1
End If
file = Dir
Wend
i = i + 1
Wend
End Sub
excel vba
add a comment |
up vote
0
down vote
favorite
I've got some VB code which loops files in folders and prints their name and size into an excel sheet.
The code picks up the folder name from the top row.
If I click on the link to the folder from Excel, I can see the items in the folder. If I point to a different folder, it works fine, however when set to a specific folder "\serverd$folder1folder2folder3", it returns nothing.
In the folder specified above, I have read only access. Is this why I can't see the results?
Does anyone know how to amend the VB to show the files?
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, file As Variant, n As Long
Dim i As Long, a As Long, filesiz As Long
Range(Cells(2, 1), Cells(100000, 10)).Delete
i = 1
While (i <= 10)
directory = Cells(1, i).Value
If directory = "" Then
Exit Sub
End If
file = Dir(directory, vbNormal)
n = 2
While (file <> "")
If InStr(file, ".sub") = 0 And InStr(file, ".blb") = 0 Then
Add = 0
If i > 1 Then
While (InStr(Cells(n + Add, 1), file)) = 0 And Cells(n + Add, 1).Value <> ""
Add = Add + 1
Wend
End If
While (Cells(n + Add, i).Value <> "")
Add = Add + 1
Wend
filesiz = FileLen(directory & file)
Cells(n + Add, i).Value = file & " " & filesiz '& " " & FileDateTime(directory & file)
n = n + 1
End If
file = Dir
Wend
i = i + 1
Wend
End Sub
excel vba
1
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've got some VB code which loops files in folders and prints their name and size into an excel sheet.
The code picks up the folder name from the top row.
If I click on the link to the folder from Excel, I can see the items in the folder. If I point to a different folder, it works fine, however when set to a specific folder "\serverd$folder1folder2folder3", it returns nothing.
In the folder specified above, I have read only access. Is this why I can't see the results?
Does anyone know how to amend the VB to show the files?
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, file As Variant, n As Long
Dim i As Long, a As Long, filesiz As Long
Range(Cells(2, 1), Cells(100000, 10)).Delete
i = 1
While (i <= 10)
directory = Cells(1, i).Value
If directory = "" Then
Exit Sub
End If
file = Dir(directory, vbNormal)
n = 2
While (file <> "")
If InStr(file, ".sub") = 0 And InStr(file, ".blb") = 0 Then
Add = 0
If i > 1 Then
While (InStr(Cells(n + Add, 1), file)) = 0 And Cells(n + Add, 1).Value <> ""
Add = Add + 1
Wend
End If
While (Cells(n + Add, i).Value <> "")
Add = Add + 1
Wend
filesiz = FileLen(directory & file)
Cells(n + Add, i).Value = file & " " & filesiz '& " " & FileDateTime(directory & file)
n = n + 1
End If
file = Dir
Wend
i = i + 1
Wend
End Sub
excel vba
I've got some VB code which loops files in folders and prints their name and size into an excel sheet.
The code picks up the folder name from the top row.
If I click on the link to the folder from Excel, I can see the items in the folder. If I point to a different folder, it works fine, however when set to a specific folder "\serverd$folder1folder2folder3", it returns nothing.
In the folder specified above, I have read only access. Is this why I can't see the results?
Does anyone know how to amend the VB to show the files?
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, file As Variant, n As Long
Dim i As Long, a As Long, filesiz As Long
Range(Cells(2, 1), Cells(100000, 10)).Delete
i = 1
While (i <= 10)
directory = Cells(1, i).Value
If directory = "" Then
Exit Sub
End If
file = Dir(directory, vbNormal)
n = 2
While (file <> "")
If InStr(file, ".sub") = 0 And InStr(file, ".blb") = 0 Then
Add = 0
If i > 1 Then
While (InStr(Cells(n + Add, 1), file)) = 0 And Cells(n + Add, 1).Value <> ""
Add = Add + 1
Wend
End If
While (Cells(n + Add, i).Value <> "")
Add = Add + 1
Wend
filesiz = FileLen(directory & file)
Cells(n + Add, i).Value = file & " " & filesiz '& " " & FileDateTime(directory & file)
n = n + 1
End If
file = Dir
Wend
i = i + 1
Wend
End Sub
excel vba
excel vba
edited Nov 7 at 18:20
GSerg
58.3k14100215
58.3k14100215
asked Nov 7 at 17:10
Cathy
1
1
1
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28
add a comment |
1
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28
1
1
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194435%2fvb-excel-dir-function-on-folder-with-security%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Is the directory shared? I avoid using the administrative share whenever possible.
– Jacob H
Nov 7 at 17:28