Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Command Button Macro To Close Document Then Delete File
It would be very much appreciated if someone could help me figure out why the
kill statement is not working in this macro. When the button is clicked, it closes the file but does not delete it from where the file is saved to. Private Sub CommandButton1_Click() Dim Doc As Document Dim DocPathName As String Set Doc = ActiveDocument DocPathName = Doc.FullName 'Check that file exists If Len(DocPathName) 0 Then 'First remove readonly attribute, if set SetAttr DocPathName, vbNormal End If 'Then delete the file Doc.Close wdDoNotSaveChanges Kill DocPathName End Sub |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
Command Button Macro To Close Document Then Delete File
Assuming the command button and the code you showed are stored in the
document itself, closing the document unloads the code from memory. That instantly stops the macro, so it never gets to the Kill statement. If you want this to work, you have to store the code in a template, either one in Word's Startup folder or the Normal.dot template. Also, the button should be on a toolbar, not in the document itself. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Wed, 24 Jun 2009 13:29:01 -0700, JBark wrote: It would be very much appreciated if someone could help me figure out why the kill statement is not working in this macro. When the button is clicked, it closes the file but does not delete it from where the file is saved to. Private Sub CommandButton1_Click() Dim Doc As Document Dim DocPathName As String Set Doc = ActiveDocument DocPathName = Doc.FullName 'Check that file exists If Len(DocPathName) 0 Then 'First remove readonly attribute, if set SetAttr DocPathName, vbNormal End If 'Then delete the file Doc.Close wdDoNotSaveChanges Kill DocPathName End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
assign a macro to a command button | Microsoft Word Help | |||
how to close word file from command line | Microsoft Word Help | |||
How do I assign a macro to a command button | Microsoft Word Help | |||
Macro Text on Command Button gone in email | Microsoft Word Help | |||
automate command button in a macro | Mailmerge |