Problem with getfolder

brkkrkmz112

New Member
Joined
Oct 24, 2016
Messages
43
Hi,

I am trying to store the files by using getfolder but even there are 6 different types of files my object only store four of them.

The only thing I can notice as difference is that the files that are ignored have very long file name.


As you may see in the link below, count is indicates as 6 but there are only 4 item below.

Thanks in advance.


https://i.imgyukle.com/2019/10/10/Ex4msI.jpg


Code:
Sub Makro2()

Dim objOL As New Outlook.Application
Dim Msg As Outlook.MailItem
Dim oldName
Dim newname As String


Dim fso As New FileSystemObject


Dim mysource As Object
Dim p1 As String
Dim p2 As String
Dim i As Long
Dim Files As Variant


For i = 6 To 4872
p1 = Cells(i, 1)


p2 = "C:\Y"
Shell "explorer.exe " & p1, vbNormalFocus
Set mysource = fso.GetFolder(CStr(p1))


For Each Files In mysource.Files


If Files.Type Like "Outlook*" Then


Set Msg = objOL.Session.OpenSharedItem(Files)
Msg.Display


fso.CreateFolder "C:\Y\" & i


Msg.SaveAs "C:\Y\" & i & "\" & Right(Files.Name, 50) & ".msg", olMSG


     Msg.Close olDiscard
     
End If


Next Files


Next i


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Is there a way in which you can shorten the file names (and path)? You can check the length of the intended path + filename to see if it is longer than 256 characters using the function Len(). If so, make a new filename, using for instance the system time (time) ans saving the file under this new name in the path.
 
Upvote 0

Forum statistics

Threads
1,224,753
Messages
6,180,747
Members
452,996
Latest member
nelsonsix66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top