Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Folder delete code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pete - 30 Sep 2006 11:19 GMT
New to this group so Hi to you all, Im after some help as Im new to
VBA/code and its adictive.

Im after help finishing the code below off, I would like to add a
commandbutton to allow the selected files to be deleted from the target
folder.

Private Sub CommandButton1_Click()

activeDir = "C:\my path"

documents.Open (activeDir & "\" & ListBox1.Value)
RAOPEN.hide

End Sub

Private Sub ListBox1_Click()

End Sub

Private Sub UserForm_Initialize()
Dim objFSO As Object, TargetFolder As Object, FC As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set TargetFolder = objFSO.GetFolder("C:\my path")
Set FC = TargetFolder.Files
HowMany = FC.Count

For Each File In FC
ListBox1.AddItem (File.Name)
Debug.Print File.Name
Next File

End Sub

Regards

Pete
Pete - 30 Sep 2006 11:39 GMT
Appoliges I meant delete file from folder and not FOLDER

> New to this group so Hi to you all, Im after some help as Im new to
> VBA/code and its adictive.
[quoted text clipped - 34 lines]
>
> Pete
Helmut Weber - 30 Sep 2006 13:36 GMT
Hi Pete,

just to get you started.
this is the way, i would try it:

Option Explicit
Const sPath = "C:\test\word\"
' -------------------------
Private Sub CommandButton1_Click()
  Documents.Open (sPath & ListBox1.Value)
  Me.Hide
End Sub
' -------------------------
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sFulname As String
With ListBox1
  sFulname = sPath & .List(.ListIndex)
  Kill sFulname
  .RemoveItem .ListIndex
End With
End Sub
' -------------------------
Private Sub UserForm_Initialize()
Dim sFile As String
sFile = Dir(sPath, vbNormal)
While sFile <> ""
  ListBox1.AddItem sFile
  sFile = Dir
Wend
ListBox1.ListIndex = 0
End Sub

Lots of error handling is still missing.

Whether you want to use dir() or the filesystem.object,
is up to you. Some use it, some avoid it.

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Pete - 30 Sep 2006 14:13 GMT
Thanks Helmut

Just a quick question

will your code fit in with my existing code as this currently works
well?

> Hi Pete,
>
[quoted text clipped - 42 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 30 Sep 2006 14:32 GMT
Probably not,

you would have to replace most of your code.

But adapting to your code
what's in the double-click event only,
shouldn't be too difficult.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Pete - 30 Sep 2006 16:12 GMT
Any sugestions how I get my existing code to carryout delete file
function?

> Probably not,
>
[quoted text clipped - 11 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Pete - 30 Sep 2006 17:03 GMT
Hi

I have managed to get it working utilising some of your code many
thanks

> Any sugestions how I get my existing code to carryout delete file
> function?
[quoted text clipped - 14 lines]
> > Win XP, Office 2003
> > "red.sys" & Chr$(64) & "t-online.de"

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.