Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
JBark JBark is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
assign a macro to a command button Tom Microsoft Word Help 1 March 21st 09 04:24 PM
how to close word file from command line MAHESH SVLY Microsoft Word Help 0 August 31st 07 11:18 AM
How do I assign a macro to a command button Kooljay2 Microsoft Word Help 2 July 18th 06 03:01 PM
Macro Text on Command Button gone in email SueKuKu Microsoft Word Help 3 May 8th 06 11:55 PM
automate command button in a macro Newbie Mailmerge 0 July 29th 05 09:05 PM


All times are GMT +1. The time now is 12:30 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"