Can't delete file after renaming due to Word file handle still present. Error staes document is still in use but it's really not. Worked fine in 2007 but not in 2010.

I have some code associated with a Word Template. The template is opened, filled out and saved via a routing in vba. This all works fine in older 2007 version (which is version it was originally created in). Once this file is saved, the user can change the
date in a text box and re-save document. The code saves using the new date for part of new file name and then deletes that older file from the server. It fails at the delete function because the newer version of word is not dropping the file handle from the
first named file when user saves it to the new filename. In older version (2007) this handle was released as soon as file was saved to a different name. I can't seem to figure out how to release the old document filename so the old document file can be deleted.
I hope I explained this well enough.
Here's the code that woeked in version 2007 but fails in version 2010.
Option Explicit
Dim CAPEX01 As MSForms.ComboBox
Dim CAPEX02 As MSForms.ComboBox
Dim LocalPath As String
Dim NetPath As String
Dim OldPath As String
Dim OldPathNet As String
Dim DocName01 As String
Dim DocName02 As String
Dim DocName03 As String
Dim DocName04 As String
Dim DocName As String
Dim DocNameold As String
Dim TestDocName As String
Dim filesys
Dim newfolder
Sub AutoOpen()
ActiveDocument.ActiveWindow.View.Type = wdPrintView
TestDocName = ActiveDocument.TextBox2
OldPathNet = "\\yourPath\" & TestDocName & "\"
End Sub
Sub AutoNew()
TestDocName = ActiveDocument.TextBox2
OldPathNet = "\\yourPath\" & TestDocName & "\"
 ComboBox1.Locked = False
 ComboBox1.Enabled = True
 FillList1
 FillList2
 End Sub
Sub DeleteOldDoc()
OldPathNet = "\\yourPath\" & TestDocName ' & "\"
DocNameold = OldPathNet & TestDocName & "-" & DocName02 & "-" & DocName03 & "-" & DocName04 & ".doc"
    If Not TestDocName = DocName01 Then
        Set filesys = CreateObject("Scripting.FileSystemObject")
    If filesys.FileExists(DocNameold) Then
        filesys.DeleteFile (DocNameold), True      
 'I get file permission error here
    End If
    End If
If DocName01 <> "" Then
If Not TestDocName = DocName01 Then
If Not TestDocName = "" Then
    MsgBox "Project Proposal Has Been Moved From Year " & TestDocName & " To " & DocName01 & ""
End If
End If
End If
TestDocName = DocName01
End Sub
'''''''Document path functions''''''
Sub chkpath()
Set filesys = CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists("\\yourPath\") Then
   newfolder = filesys.CreateFolder("\\yourPath\")
End If
If Not filesys.FolderExists("\\yourPath\" & DocName01 & "\") Then
    newfolder = filesys.CreateFolder("\\yourPath\" & DocName01 & "\")
End If
End Sub
''''''Save Function''''''
Private Sub CommandButton1_Click()
DocName01 = ActiveDocument.TextBox2
DocName02 = ActiveDocument.TextBox4
DocName03 = ActiveDocument.TextBox1
DocName04 = ActiveDocument.ComboBox1.Value
chkpath
NetPath = "\\yourPath\" & DocName01 & "\"
DocName = NetPath & DocName01 & "-" & DocName02 & "-" & DocName03 & "-" & DocName04
ActiveDocument.SaveAs2 FileName:=DocName, FileFormat:=wdFormatDocument
 ComboBox1.Locked = True
 ComboBox1.Enabled = False
 ComboBox2.Locked = True
 ComboBox2.Enabled = False
 TextBox1.Locked = True
 TextBox1.Enabled = False
 TextBox3.Locked = True
 TextBox3.Enabled = False
 TextBox4.Locked = True
 TextBox4.Enabled = False
 DeleteOldDoc
End Sub
Sub FillList1()
Set CAPEX02 = ActiveDocument.ComboBox2
  With CAPEX02
      .AddItem "CASTING", 0
      .AddItem "HOT ROLLING", 1
      .AddItem "COLD ROLLING", 2
      .AddItem "FINISHING", 3
      .AddItem "PLANT GENERAL", 4
      .AddItem "MOBILE EQUIPMENT", 5
  End With
End Sub
 Sub FillList2()
 Set CAPEX01 = ActiveDocument.ComboBox1
  With CAPEX01
      .AddItem "A Name", 0
      .AddItem "Another Name", 1
  End With
End Sub
Private Sub CommandButton2_Click()
    UserForm1.Show
End Sub

mogulman52 and Don,
I went back and looked at my code and had already updated it to SaveAs in the new docx format. It still holds the lock handle in place until Word closes, unlike earlier versions which released the lock handle when you did a SaveAs.
As a note, all my Word and Excel macro-enabled (dotm & xltm) templates are read only and are never filled in, prompting the user for a file name on any close event or if they run the code gets auto-named. I do the SaveAs and concatenate the file name
from data on the document (or sheet) that has been filled in. During the SaveAs the docx gets saved to a network folder and also on a local folder. The lock gets renamed to the filename and remains until Word is closed.
So my code still fails at the point noted below while trying to delete an old filename version after the file has been saved as a new filename in a new folder. So....
The code is looking in the last folder where the docx file was saved for the older filename so it can be deleted. The newest docx version has already been saved in a different folder and has a new lock handle of its own. That lock is not my problem, it's
the older file lock which really exists in the same folder as the first filename that the docx was saved to. It does not release that lock until I exit Word. My work around has been to instruct all users to manually delete the older version file.
The other odd thing is this only happens when I run it from code, if you manually go through these steps with the SaveAs menu drop-downs in Word it will release the lock handle???
Hope this isn't to confusing and thanks for all your suggestions and help.
Sub DeleteOldDoc()
OldPathNet = "\\yourPath\" & TestDocName ' & "\"
DocNameold = OldPathNet & TestDocName & "-" & DocName02 & "-" & DocName03 & "-" & DocName04 & ".doc"
If Not TestDocName = DocName01 Then
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(DocNameold) Then
filesys.DeleteFile (DocNameold), True 'I get file permission error here- lock handle is still present from last SaveAs command in last folder where previous version of file was saved.
End If
End If
If DocName01 <> "" Then
If Not TestDocName = DocName01 Then
If Not TestDocName = "" Then
MsgBox "Project Proposal Has Been Moved From Year " & TestDocName & " To " & DocName01 & ""
End If
End If
End If
TestDocName = DocName01
End Sub
Glenn

Similar Messages

  • Can't delete podcasts from iPod Touch!!!  They still remain using space!!

    Ok ok, look. I can make them not SHOW UP anymore, but they are STILL ON THE IPOD.
    If I make a smart playlist where podcast=true and move it to the ipod, i can SEE they are still on the ipod!! But you cannot delete files from the smart playlist!!
    I dont want to delete them from iTunes because I want to still have them archived on my computer.
    If i deselect all podcasts from the sync menu, then sync, they are only removed from the podcasts display on the ipod... the actual files are still taking up space on the ipod
    APPLE PLEASE FIX THIS. some of us WANT manual control of the files, not just sync this and that.
    right now, my ONLY solution I can find is to restore the ipod, reload all my music i want to keep, reload my apps, etc etc.
    ALL I WANT TO DO IS DELETE SOME PODCASTS!!!
    Does ANYONE have a workaround?!?!

    TheDetourist wrote:
    I dont want to delete them from iTunes because I want to still have them archived on my computer.
    just to say, you can delete items from itunes, and still have them stored on your computer, just click 'keep file' and it will be removed from itunes yet still be stored in the podcast file (or songs etc.)
    i'm not sure whether this will solve your problem, and i haven't had much experience with smart playlists, so i'm not sure how to get them to do what you want, but I have some podcasts that i want to sync automatically, and others that i don't. last night i worked out how to do it.
    1. my ipod is set to sync manually
    2. under the podcasts tab, it is set to sync '10 least recent unplayed' (there are several different options to choose to your requirements) episodes of selected podcasts.
    3. in the podcasts boxes, the ones i want to sync are checked.
    4. these now sync to my ipod.
    5. but, because i am manually managing my songs etc. i can still drag and drop any others that i want to my ipod.
    but i'm a bit confused. you are using smart playlists to transfer your podcasts to your ipod. as i say, i'm not too familiar with smart playlists, but is there a reason why you don't just drag and drop them to the ipod/sync them using just the podcast syncing feature?

  • LR4, MacOS Can't delete files "ag.library.expandAllStacks" Error

    Hi I have LR 4.3, Camera Raw 7.3
    Until yesterday I was able to delete pictures, using the contextual menu or the delete key. I got the message asking me if I wanted to delete them from disk or from the catalog.
    But now, that popup message doesn't appear. The picture is not removed, just nothing happens.
    I checked the logs and this is the error message:
    performCommandDesc could not perform command ag.library.expandAllStacks (Command was disabled.).
    I uninstalled LR moving it to the trash. Then I deleted the com.adobe.Lightroom4.plist and I also removed the folder ~/Library/Application Support/Adobe/Lightroom.
    I rebbooted the machine and installed it again. But the issue is still there, with the same error message.
    I verified the disk and checked file permissions.
    I also tried to use another catalog from a backup.
    Nothing, same error.
    One anusual thing that I did before the error was to install the "HDRsoft Merge to 32-bit HDR Plug-in for Lightroom - Version 1.0"
    I removed it but the error was still there. After the re-install I didnd't install that plug-in again so if it was the problem, it shouldn't be after the clean installation that I did again.
    Please help!
    Machine Specs:
    Man mini server mid 2011
    2GHz Intel core i7
    Ram: 8G
    Graphics: Intel HD Graphics 3000 512MB
    OSX: 10.8.2 (12C60)
    Thanks.
    P

    Try,in the Lightroom preferences dialog, General tab click on "Reset all warning dialogs".

  • I can´t delete files in trash. It stops after a short time undone. What can I do?

    I can´t delete files in trash . It stops after a short time undone.
    What can I do? There are 52 files in trash, but if I click the button "sure empty" it shows 11.313 files to delete .
    I would be very greatful for your help!

    Stronger medicine may be needed, but try this first
    Force the Trash to empty using the Option key
    This technique uses a hidden feature of Mac OS X to force the Trash to empty. Perform the following steps in the order specified:
    Press and hold the mouse button on the Trash icon in the Dock. The context menu for Trash will display.
    Press and hold the Option key or the Shift-Option keyboard combination,
    Select Empty Trash from the context menu for Trash.
    Release the keys pressed and held in step 2.
    http://www.thexlab.com/faqs/trash.html#Anchor-Files-46919
    You are posting in the iMac PPC forum, but it looks like you have an Intel Mac. Get Trash It if you have an Intel.
    http://www.macupdate.com/app/mac/8214/trash-it!

  • Can I delete files on Macbook after using TM?

    I just used TM for first time. I need to free up HD space on Macbook before I run out. Do I need to move files to external or can I delete them after using TM? Do not want to loose the data that I have.

    Apple says that the Time Machine volume can share space with other files but recommends that Time Machine have its own volume. If you put the files on the same volume as Time Machine you could not use Time Machine to back them up. Also, 160GB is on the smallish side for a Time Machine volume so taking up space for extra files will mean that you will run out of space for backups more quickly.
    External drives can be bought for less than what Leopard costs and extra storage is always a worthwhile investment.

  • Can I delete CS4 after CS5 upgrade?

    Can I delete CS4 after I installed the CS5 upgrade, or will that have a negative effect?
    Thanks

    If you don't want to keep the older version:
    uninstall the older version first, BEFORE installing the new version.
    The Adobe Uninstallers have a nasty habit of messing with essential support files of the new version because they mistake them for the older versions.  When that happens, you have to jump through hoops just to uninstall the damaged version, as not even the Uninstaller will work on it. (You would need something called the CS3Clean Script, CS4Clean Script aor CS5Clean.  Avoid having to go there.  Honest.)
    All Adobe upgrades are FULL INSTALLERS.  The Upgrade installer will simply ask you for the old serial numbers when it doesn't find an older qualifying version installed.
    Once more:
    Do NOT uninstall an older version after upgrading to a new one; do it BEFORE.
    Foretold is forewarned.
    Wo Tai Lao Le
    我太老了

  • Where can I find the Start up disk and how can I delete file from it.

    where can I find the Start up disk on theMac Book Air?
    How can I delete files from it?

    The startup disk is the internal SSD in your MBA.  You may delete files by draging the file  to Trash (or clicking on them and then execute COMMAND+Delete).  Then empty Trash.
    Ciao.

  • Can't delete file from Trash

    Hi,
    I received a JPG file which I downloaded that caused my Mac to run extremely slowly.
    I deleted it to Trash and the Mac is now working normally but when I go to empty the trash it doesn't delete the file because it says the file is still in use. Even when I select continue it still doesn't delete.
    How can I get rid of this file permanently from the Trash?
    Thanks.

    very strange that finder would be using it.
    do this. paste the following into Script Editor (it's in /Applications/utilities) and press the run button.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder" to quit
    do shell script "rm -f /Users/adrianmusolino/.Trash/image001.jpg"
    delay 3
    tell application "Finder" to run</pre>

  • Can't delete files and need to restart lightroom

    hello
    have you ever seen this problem?
    when using lightroom 1.3.1 on PC, I can't delete files. Lightroom doesn't work and i need to restart the program.
    Thanks for your answers

    having same problem here. I used to have the option to delete, but it seems to have dissapeared. I can delete but if I look in recycle its not there. If I go to undo, it says my last action was to delete the keyword which also removed it from the catalog. weird............

  • Can't delete files in iTunes 10.4 (80) OS 10.7 Delete in the edit menu is not hi-lighted?

    Can't delete files in iTunes 10.4 (80) OS 10.7 Delete in the edit menu is not hi-lighted. Any sugestions? I have three Mac's and they all have the same problem.

    Gmatos, when I high-light and drag file from iTunes to my trash the usual promt of "do I want to remove it" followed by by the uual "do I want to keep the file or remove that from my library" comes up too. I click "dont keep file" and it is gone from my itunes and my library an my HD. It's exactly the same as it's always been except annoyingly this is the only way I can do it as the delete button just doesn't work in this latest version.
    Hope this is clearer for you.

  • Is there a trash can for deleted files in Photoshop 10?

    is there a trash can for deleted files in Photoshop 10?

    Thank you so much for replying.  Yes, I'm using Photoshop Elements 10.  You may save me weeks of work.  Again "Thanks so much for replying to my problem.
    Howard
    [email protected]

  • My mac book startup disk is full and when I start it, it give me a blank blue screen. I have tried the shift and I started in safe mode, and it gave me the stars screen. How can I delete files to fix the problem

    My mac book startup disk is full and when I start it, it give me a blank blue screen. I have tried the shift upon start
    and I started in safe mode, and it gave me the stars screen. How can I delete files to fix the problem

    1. Start up in Safe Mode.
        http://support.apple.com/kb/PH11212
    2. Empty Trash.
        http://support.apple.com/kb/PH10677
    3. Delete "Recovered Messages", if any.
        Hold the option key down and click "Go" menu in the Finder menu bar.
        Select "Library" from the dropdown.
        Library > Mail > V2 > Mailboxes
        Delete "Recovered Messages", if any.
        Empty Trash. Restart.
    4. Delete old iOS Devices Backup.
        iTunes > Preferences > Devices
        Highlight the old Backups , press “Delete Backup” and then “OK”.
        http://support.apple.com/kb/HT4946?viewlocale=en_US&locale=en_US
    5. Re-index Macintosh HD
       System Preferences > Spotlight > Privacy
       http://support.apple.com/kb/ht2409

  • Ok, so it appears that my photo gallery and video gallery decided to delete themselves? Is there a trash can or deleted file where I can recover them? Please help

    Ok, it seems that my photo gallery and video gallery decided to
    delete themselves. Is there a way to recover them perhaps from
    a trash can or deleted file? I have a Android

    appreciate your reply
    1. i do not see a trashcan iconwhen i open the photos.
    2. the photos are NOT in the 'camera roll' they are in a folder called 'iPad photos' (which is in the 'albums' section of the iPad)
    3. i have re-set the iPad numerous times in order to try and resolve this. each time it is the same - no trashcan.
    4. i have no method of 'moving' the photos to another folder - only the option to 'add to' a 'new folder'. since thsi won't delete the original photos, there is little point in trying this.
    5. i'm guessing your next suggestion will be to completely back up and re-set my iPad? is that really what i should be doing here? surely... surely.... please, this should be a simple - select>trashcan>delete process and not something i have to spend half my working day trying to resolve! seriously, seriosly, unimpressed with Apple over this issue. it's about time that Apple gave the power back to the user on devices like these. i can understand now why people jailbreak their iPads... there rant over - but please consider my feelings over this issue.

  • HT204408 Can I delete files in "All My Files" under Finder and Favorites without deleting them in the actual folders?  If they will be deleted from the original folders then how do I put them on the external hard drive to save the documents, photos, and v

    Can I delete files in "All My Files" under Finder and Favorites without deleting them in the actual folders?  If they will be deleted from the original folders then how do I put them on the external hard drive to save the documents, photos, and videos?

    Switch to the Finder app and open its preferences.
    Remove the check mark on the items you don't want displayed in the Sidebar tab.
    The originals are not removed from the machine.

  • I can't login, keep geting "Your  Startup Disk is Full" and asking me to delete file. if I cant login how can I delete files? Please help

    I Keep getting "your startup disk is full" ..... "You need to make more space available on your startup disk by deleting file..."  If I can't have an acess, how can I delete files. Please help..

    That means the hard drive of your computer is full, and you don't have enough free space on your computer, to do what you are trying to do. 
    You need to clear up space on your computer. 
    If you hard drive is full, check the following places to ensure they are not holding unwanted data.
    - your trash can in the dock
    - if you use iPhoto, your trash in iPhoto - launch iPhoto, and select trash in the left hand column.  iPhoto has it's own trash, and is often overlooked
    - your download folder - finder / home user / downloads - every time you download something, it stores it here. This is often overlooked as well
    - do you have more than one user on the computer?  If you do, ensure they are needed.  If not, delete them, and the contents of their home folders
    If you hard drive is very full, you may want to consider the following:
    - putting in a newer larger hard drive - (call you local apple store for prices on this)
    - deleting data off your computer
    - moving data to an external drive - (iPhoto Libraries, iTunes Libraries or iMovie events, as they are the biggest space hogs)

Maybe you are looking for

  • Installation problem with CS4 on Windows 7

    I have been trying to install CS4 to a new HDD. It is from the (licensed) disk. It stops at the Initializing phase: "Checking System Profile", getting stuck at 90%. Here is the screen message: I have turned off any antivirus scanning, even turned off

  • Nested tables causes trouble in RoboHelp FM Import

    May be someone here in this forum knows a solution or a workaround for my trouble with a FrameMaker Import in RoboHelp. Background: To generate context sensitive Windows HTML-Help a FrameMaker document is imported into RoboHelp. There are lots of nes

  • Spaces and 'is numeric' validation.

    Hello everyone, I'm using a simple application and in one field, i have a ' is numeric ' validation on a text field item. Everything works fine except that when i enter a space ' ' , the validation does not stop the request and i end up with ORA-0650

  • Why aren't all of my photos showing up that I am trying to save directly from my email? particularly jpegs?

    Why aren't all of my photos showing up that I am trying to save directly from my email on my iPad2? particularly jpegs? Usually i just hold my finger down and am able to save all the photos attached in an email and now only certain photos are actuall

  • Global Automatic Activity - Process to Process

    Hi, How can we invoke another process from one process using a Global automatic activity..Is PAPI the only way? How can we use PAPI code inside of a Global Automatic Activity to call another process?v Any examples? Edited by: user647659 on Oct 27, 20