Consulting

Results 1 to 9 of 9

Thread: Error Message 4605

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Error Message 4605

    While attempting to run the marco below I get the following error on the line bolded in the macro:

    4605 This command is not available

    [VBA] Sub replace_client(sPath As String)
    Dim oDoc As Word.Document

    With Application
    Set oDoc = .Documents.Open(sRoot & sPath)

    With oDoc.Content.Find
    .ClearFormatting
    .Text = "Student"
    With .Replacement
    .ClearFormatting
    .Text = "Client"
    End With
    .Execute Replace:=wdReplaceAll
    End With

    oDoc.Close True
    End With

    Set oDoc = Nothing
    End Sub
    [/VBA]

    While looking for this error explaination on the net it looks like one of the possibilities is a bad file name. The files I am trying to loop through have special characters in the file names (-). Could this be causing the problem?
    If so is there a way to loop through the files and remove the spaces. There are around 300 files all named this way.

    In previous tests I was using files with straight data. The files I am going through, have tables, and other forms in them.
    Thanks
    Peace of mind is found in some of the strangest places.

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Please clarify. Are you stateing that if you do a test run with folders and files, normally named, you do NOT get this error?

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hiya,

    I'm a bit confused... I would expect any issues relating to bad file names to cause an error on the document.Open command, but your error is on the Execute of Find, correct?

    Word can be a little tempermental about things sometimes, it might be that "the command is not available" because Word or the target document's window isn't active.
    K :-)

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Indeed a very strange error.

    For the record what version of Word are you running?

    Sometimes left over instances of Word can cause this strange error. Close Word and see in taskmanager if an instance of Winword.exe is running.

    If it is kill it (Make sure Outlook isn't running as well if Word is default maileditor).
    Or Reboot your system and run the code again.

    But I'm very interested in the result of the question Gerry asked you.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Well I figured it out. Should have looked at this first. Stupid oversight. All the documents were Protected as they were meant to be templates so no one can chaget the format. After unprotecting one works fine. A bit of a pain in the butt because now I have 300+ documents to unprotect, find and replace then protect again. MOS your code from the other day works great. Can you suggest where to dothe unprotect and protect in the code. Thanks
    Peace of mind is found in some of the strangest places.

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Austen,

    You're welcome and glad it works fine.

    You say you have protected documents but you don't say which type of protection? There are many types.

    I've arranged in the code for all Protectiontypes by reading which one applies and then remember it and put it back if the document had protection to begin with.

    I do wonder however where the optional parameters are from the sub? Yesterday there where three....

    Well I've put them back let it have a spin: [VBA]
    Sub replace_client(sPath As String, sSearch As String, sReplace As String)
    Dim oDoc As Word.Document
    Dim bProtected As Boolean
    Dim lProtect As Long

    With Application
    Set oDoc = .Documents.Open(sRoot & sPath)
    With oDoc
    If .ProtectionType <> wdNoProtection Then
    bProtected = True
    lProtect = .ProtectionType
    .Unprotect Password:=""
    End If

    With .Content.Find
    .ClearFormatting
    .Text = sSearch
    With .Replacement
    .ClearFormatting
    .Text = sReplace
    End With
    .Execute Replace:=wdReplaceAll
    End With

    If bProtected Then
    .Protect Type:=lProtect, NoReset:=True, Password:=""
    End If
    .Close True
    End With
    End With

    Set oDoc = Nothing
    End Sub
    [/VBA]

    Later..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    If I understand correctly, these are templates. Do you mean real .DOT files? Not .DOC files that are being used as templates.

    As Joost asked, what KIND of protection? Are they using formfields? Or are they Document protection?

    If they are formfields (and you need forms protection for them to function), I would suggestion having text NOT in the formfields placed in UNprotected sections. That way you can edit them easier.

    To expand this, if you have 300+ documents (templates), if possible, you may want to consider consolidating them into fewer documents. Then have a UserForm that determines which larger document is needed, then depending on the logic of the user input, builds a document for them. This can be dome through a removal process (a document that originally starts with five or six document structures, and removes the parts not needed; or a document control document, that inserts parts that are needed.

  8. #8
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Well if you go to Tools>Unprotect Document it will allow you to make the changes. however the areas that you are able to type in are not able to expand then such as a text box. I am doing this for my wife for her work so I am a little fuzzy as to what they did to the whole thing. Oh well, it works as I need it to. Thanks MOS. Solved.
    Peace of mind is found in some of the strangest places.

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    You're Welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •