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









share|improve this question




















  • 1




    Is the directory shared? I avoid using the administrative share whenever possible.
    – Jacob H
    Nov 7 at 17:28















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









share|improve this question




















  • 1




    Is the directory shared? I avoid using the administrative share whenever possible.
    – Jacob H
    Nov 7 at 17:28













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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings